Override type checking in contract call
See original GitHub issueOne way that MetaMask can look up a user’s ETH or ERC20 balance is to call a balance checking contract: https://etherscan.io/address/0xb1f8e55c7f64d203c1400b9d8555d050f94adf39#code
Specifically, we call the function balances(address[] users, address[] tokens) external view returns (uint[])
. We make the call directly on a Contract
object instantiated from the ABI.
To check a user’s ETH balance, the contract makes a special case for the address 0x0
(note that this is not intended to be the null
/0-address) when encountered in the tokens
array. ethers
, however, treats 0x0
as the invalid address it is. This is very reasonable, but can we bypass the type checking somehow?
(Alternatively, if anyone knows of another balance checking contract, that would also be helpful.)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hah! I investigated further, and we were not handling the ethers
BigNumber
type correctly. It works perfectly. Thank you for your help!If you use the AddressZero, it seems to work fine for me. 😃