Etherscan – Why Does Implementation Contract Return Wrong Token Symbol When Called from Ethers.js?

ethers.jsetherscanproxy-contracts

I am trying to get the symbol and decimals for tokens. I have come to realize that some contracts are mere proxies and their implementations are somewhere else. This is where the confusion kicks in.

I have successfully gotten the address of the implementation contract, and from it I am able to get the ABI. However, the implementation contracts data such as symbol or decimals is different than that of proxy contract.

For example, if you check WBTC token here – https://polygonscan.com/token/0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6#readContract

In Read as Proxy you can see that the symbol is WBTC, however if you go to its implementation contract at https://polygonscan.com/address/0x7ffb3d637014488b63fb9858e279385685afc1e2#code, it says USDT. This is exactly what I am getting in my code.

How do I get WBTC for WBTC and not USDT? Thank you!

Best Answer

How the proxy pattern usually works is that the main token address - 0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6 in your case - holds the contract's storage, and forwards all function calls to the implementation contract using delegatecall. This will execute the functions in implementation contract on the storage of the main proxy contract.

So if you want to read the right storage values, you need to read them from the main proxy contract.

You can use the implementation contract's ABI on the main proxy contract itself.

Related Topic