6

Normally I just do this on python:

token = web3.eth.contract(address=contract_address, abi=abi)
balance_in_wei = token.functions.balanceOf(wallet).call()

However, when the function isn't in the "Read Contract" tab, this code wouldn't work at all. enter image description here

The balanceOf function can be found in "Read as Proxy". enter image description here

How could I call this function as proxy in web3 py? For context, I'm trying to get my balance of USDC: https://etherscan.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

Austin
  • 143
  • 3
  • 12

4 Answers4

9

I found your question in searching for the same issue and struggling for hours. For clear definitions the proxy contract A will point to contract B. What fixed it for me was using the ABI of the contract B and the address of contract A. Best of luck!

jbarak
  • 106
  • 1
  • 1
4

same exact way. Just pretend it's there and it should work. Instantiate the contract with the ABI that you want to call (e.g. the one with balanceOf regardless of it's actually there or not)

thefett
  • 3,873
  • 5
  • 26
  • 48
  • 1
    The reason why I asked this is because it doesn't work correctly. I used the token.functions.balanceOf(wallet).call() function but it's displaying zero, even though I have 10 on my wallet. This function works for all other tokens. – Austin Feb 11 '22 at 07:26
  • what's your abi? – thefett Mar 29 '22 at 12:29
0

I think balanceOf returns a BigNumber value that needs to be formatted for display purposes. Are you running a formatting function prior to displaying the balance? Formatting functions take a decimals argument. Standard ERC-20 tokens implement 18 decimals but the USDC contract only implements 6 decimals. So the formatter function args might need to be adjusted.

https://docs.openzeppelin.com/contracts/3.x/erc20#a-note-on-decimals https://docs.ethers.io/v5/api/utils/display-logic/#utils-formatUnits

hzhu
  • 101
  • 2
0

You have to use the address of main contract and ABi of proxy contract to use main functions of these kind of smart contracts