Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching total token supply #103

Open
pwollemi opened this issue Jan 31, 2022 · 0 comments
Open

Fetching total token supply #103

pwollemi opened this issue Jan 31, 2022 · 0 comments

Comments

@pwollemi
Copy link

export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {

export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {
  let contract = ERC20.bind(tokenAddress)
  let totalSupplyValue = null
  let totalSupplyResult = contract.try_totalSupply()
  if (!totalSupplyResult.reverted) {
    totalSupplyValue = totalSupplyResult as i32
  }
  return BigInt.fromI32(totalSupplyValue as i32)
}

In this function, if we convert the result to i32, then the upper field is cut I think.
Shouldn't it be like this?

export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {
  let contract = ERC20.bind(tokenAddress)
  let totalSupplyValue = new BigInt(0)
  let totalSupplyResult = contract.try_totalSupply()
  if (!totalSupplyResult.reverted) {
    totalSupplyValue = totalSupplyResult.value
  }
  return totalSupplyValue;
}

If I am not recognizing the correct type of i32, pls tell me.
And may many know, does this function fetch the value from the latest block or the current scanning block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant