0

I'm pulling the USDC ABI from etherscan and then passing it in to web3

erc20_dict = { 'USDC': '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' } url = f'https://api.etherscan.io/api?module=contract&action=getabi&address={contract_address}&apikey={apikey}' ret = requests.get(url) ABI = ret.json()['result'] contract = w3.eth.contract(address=w3.toChecksumAddress(erc20_dict['USDC']), abi=ABI) print(contract.functions.decimals().call()) 

but am getting the following error:

web3.exceptions.ABIFunctionNotFound: ("The function 'decimals' was not found in this contract's abi. ", 'Are you sure you provided the correct contract abi?') 

Is there a reason why the USDC ABI on etherscan doesn't contain the decimals function? I want to use this function generically to pull ABI for tokens/contracts so using the generic erc20 ABI isn't the best solution. Any ideas? Thanks!

1 Answer 1

4

This is because USDC uses a proxy contract. The proxy contract will use delegatecall to an implementation contract which will contain all the ERC-20 functions. So in your code, you don't need to get ABI from etherscan, you can use a basic ERC-20 contract's ABI and that should work for all ERC-20 token contracts. That will also help you avoid an external API call for every contract.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.