1

I tried to get USDC's meta data specifically symbol, name, decimals with ethers.js.

However I caught below data

  name: '',
  symbol: '',
  decimals: 0

Are there who meet the same situation? I call not the proxy contract but the implement contract, 0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf. I checked to see the meta data on Etherscan. https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#readProxyContract

2 Answers 2

0

Yes calling the implementation contract won't give you the values, because it is there to extend the functionality of the proxy contract, in the context of the proxy contract's storage.

All the storage variables (such as name, symbol, decimals etc.) are held in the proxy contract, so you should query that.

2
  • Thank you for your answer. You mean, I should call a function in implement contract's ABI to proxy contract?
    – ttt
    Nov 9, 2023 at 15:10
  • Yes just call exactly like you would to the implementation, except to the proxy. The proxy DELEGATECALLs to the implemenation contract. Think of the implementation like extended functionality of the proxy, using the proxy's storage.
    – Peter
    Nov 9, 2023 at 20:31
0

The contract address you provided 0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf is not the official USDC contract (at least until my knowledge cutoff in September 2021), which could be a reason for the missing metadata.

The official USDC contract on the Ethereum mainnet is 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48.

Here is how you can interact with an ERC20 token contract using ethers.js:

    const ethers = require('ethers');
    
    async function getERC20TokenMetadata() {
        // Create a provider
        let provider = ethers.getDefaultProvider();
    
        // Define the ABI (Application Binary Interface)
        const erc20Abi = [
            // Some details about the token
            "function name() view returns (string)",
            "function symbol() view returns (string)",
            "function decimals() view returns (uint8)",
        ];
    
        // The address of the ERC-20 Token
        const tokenAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";  // USDC contract
    
        // Create an instance of the contract
        const contractInstance = new ethers.Contract(tokenAddress, erc20Abi, provider);
    
        // Call the contract functions
        const name = await contractInstance.name();
        const symbol = await contractInstance.symbol();
        const decimals = await contractInstance.decimals();
    
        console.log("Name:", name);
        console.log("Symbol:", symbol);
        console.log("Decimals:", decimals);
    }

getERC20TokenMetadata();

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.