I'm attempting to get the implementation contract for a proxy using ethers (and testing it using the recently published Paypal USD: https://etherscan.io/address/0x6c3ea9036406852006290770bedfcaba0e23a0e8)
So, first I do the following, fetching the Abi from the etherscan API:
const abi = await etherscanApiClient.contract.getabi('0x6c3ea9036406852006290770bedfcaba0e23a0e8')
console.log(abi)
This produces:
[
{
constant: false,
inputs: [Array],
name: 'upgradeTo',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [Array],
name: 'upgradeToAndCall',
outputs: [],
payable: true,
stateMutability: 'payable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'implementation',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [Array],
name: 'changeAdmin',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'admin',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
inputs: [Array],
payable: false,
stateMutability: 'nonpayable',
type: 'constructor'
},
{ payable: true, stateMutability: 'payable', type: 'fallback' },
{
anonymous: false,
inputs: [Array],
name: 'AdminChanged',
type: 'event'
},
{
anonymous: false,
inputs: [Array],
name: 'Upgraded',
type: 'event'
}
]
Great, so far so good, and this aligns with the abi as it is seen on etherscan.
Then I attempt to call this function with:
const contr = await new ethers.Contract('0x6c3ea9036406852006290770bedfcaba0e23a0e8', abi, alchemyProvider)
const implementation = contr.implementation()
Which is the exact method I've used many times in the past to get, for instance, decimals or other read method results off other contracts.
However in this case, my application explodes! Reviewing my logs on alchemy, I see that the request was:
{
method:"eth_call",
params:[
{
to:"0x6c3ea9036406852006290770bedfcaba0e23a0e8",
data:"0x5c60da1b"
},
"latest"
],
id:42,
jsonrpc:"2.0"
}
Which results in the following failure:
{
jsonrpc:"2.0",
id:42,
error:{
code:-32000,
message:"execution reverted"
}
}
So my questions are:
- What's special here? Why is this abi/contract/method in particular failing to be called?
- How can I achieve this result and get the implementation contract address for a smart contract using ethers.js?