Proxy contract interaction
julian-CStack opened this issue · 8 comments
USDC (https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#code) for example, has no balanceOf
or transfer
functions in its ABI so final balanceFunction = DeployedContract.function('balanceOf');
will throw unless the balanceOf
function is manually added to the ABI string before construction of the DeployedContract
object.
Can you paste some code, please?
The contract does have the functions. Refer to "Read as Proxy" tab. Or https://etherscan.io/readContract?m=l&a=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&n=mainnet&v=0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf
I am currently fetching the ABI via etherscan's api for the USDC contract above and I do not get the functions from the 'Read as Proxy'.
The result of the abi fetch request is:
{ "status": "1", "message": "OK", "result": "[{\"constant\":false,\"inputs\":[{\"name\":\"newImplementation\",\"type\":\"address\"}],\"name\":\"upgradeTo\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newImplementation\",\"type\":\"address\"},{\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"upgradeToAndCall\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"implementation\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newAdmin\",\"type\":\"address\"}],\"name\":\"changeAdmin\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"admin\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_implementation\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"previousAdmin\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"newAdmin\",\"type\":\"address\"}],\"name\":\"AdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"implementation\",\"type\":\"address\"}],\"name\":\"Upgraded\",\"type\":\"event\"}]" }
Its entirely possible I'm missing something simple to get the actual ABI of the contract the proxy points to.
Because USDC is a proxy contract
, all the calls are forwarded to the proxied contract. So you must get the ABI of the Proxy contract.
https://ethereum.stackexchange.com/questions/122085/usdc-etherscan-abi-missing-decimals-function
Still a bit new to working with eth contracts and I thought there might be a better way to fetch the ABI of the contract that the proxy contract points to.
Looking it up manually is not an option so I will need to figure out some other way to fetch the correct ABI. Possibly like this: https://ethereum.stackexchange.com/questions/135333/is-it-possible-to-pull-proxy-contracts-through-an-ethereum-based-api
I've found a solution for you, but I am not sure if this is the best possible way of doing it:
export YOUR_API_KEY=12345678
$ curl -d "address=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" "https://api.etherscan.io/api?module=contract&action=verifyproxycontract&apikey=$YOUR_API_KEY"
# {"status":"1","message":"OK","result":"vbdpwlap3xapgkxvltjazvhqqssy2jmyhdr4a2wlrbimt9qrhm"}
$ curl "https://api.etherscan.io/api?module=contract&action=checkproxyverification&guid=vbdpwlap3xapgkxvltjazvhqqssy2jmyhdr4a2wlrbimt9qrhm&apikey=$YOUR_API_KEY"
# {"status":"1","message":"OK","result":"The proxy's (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48) implementation contract is found at 0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf and is successfully updated."}
Then in your browser (or Get command):
https://api.etherscan.io/api?module=contract&action=getabi&address=0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf&apikey=<<PUT_YOUR_API_KEY>>
I've found a solution for you, but I am not sure if this is the best possible way of doing it:
export YOUR_API_KEY=12345678
$ curl -d "address=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" "https://api.etherscan.io/api?module=contract&action=verifyproxycontract&apikey=$YOUR_API_KEY" # {"status":"1","message":"OK","result":"vbdpwlap3xapgkxvltjazvhqqssy2jmyhdr4a2wlrbimt9qrhm"} $ curl "https://api.etherscan.io/api?module=contract&action=checkproxyverification&guid=vbdpwlap3xapgkxvltjazvhqqssy2jmyhdr4a2wlrbimt9qrhm&apikey=$YOUR_API_KEY" # {"status":"1","message":"OK","result":"The proxy's (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48) implementation contract is found at 0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf and is successfully updated."}
Then in your browser (or Get command):
https://api.etherscan.io/api?module=contract&action=getabi&address=0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf&apikey=<<PUT_YOUR_API_KEY>>
This should work. Will test. I was able to successfully grab the implementation address using the method described in the SE link in:
Still a bit new to working with eth contracts and I thought there might be a better way to fetch the ABI of the contract that the proxy contract points to. Looking it up manually is not an option so I will need to figure out some other way to fetch the correct ABI. Possibly like this: https://ethereum.stackexchange.com/questions/135333/is-it-possible-to-pull-proxy-contracts-through-an-ethereum-based-api
I closed the issue as its not really a web3dart issue but a user (me) error. Thanks for getting me pointed in the right direction. Much appreciated!
@julian-CStack Any time!