Ethers.js: Random CALL_EXCEPTION calling Uniswap

Created on 1 Aug 2020  ·  5Comments  ·  Source: ethers-io/ethers.js

Hello,

i'm using latest version.

My code:
const provider = ethers.getDefaultProvider("ropsten", {
etherscan: "myapikey"
}
);
//UNISWAP_FACTORY_ADDRESS='0x9c83dCE8CA20E9aAF9D3efc003b2ea62aBC08351'
//UNISWAP_FACTORY_ABI ( the one on this page https://uniswap.org/docs/v1/frontend-integration/connect-to-uniswap/)
let contract = new ethers.Contract(UNISWAP_FACTORY_ADDRESS, UNISWAP_FACTORY_ABI, provider);
contract.tokenCount().then(currentValue => {
console.log("NUM TOKENS AVAILABLE AT UNISWAP: "+currentValue.toNumber());
}).catch(err => {
console.log(err.toString());
});

Most of the times it works and returns:
NUM TOKENS AVAILABLE AT UNISWAP: 219

But randomly it fails and return:
Error: call revert exception (method="tokenCount()", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.2)

What can be the reason?

Thanks

Most helpful comment

More info:

this works ok (and is fast):
const provider = new ethers.providers.EtherscanProvider('ropsten', mi-api-key);

this fails randomly (and is slow):

const provider = ethers.getDefaultProvider('ropsten'
    , {
        etherscan: mi-api-key
    }
);

It seems defaultprovider is not taking into account the api keys.

All 5 comments

Not able to reproduce the exact problem currently. Also, I don't think this problem would be specific to Uniswap smart contract. But I think it's possible to get this error when nodes are out of sync (on an old block number). Just to confirm that, can you print the block number when you get the error:

.catch(err => {
  console.log(err.toString());
  provider.getBlockNumber().then(console.log)
});

Thanks for the response.

I'm getting this output:
Error: call revert exception (method="tokenCount()", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.2)
8417808

I think that the block number is ok

What i have noticed is that my etherscan api key is showing 0 requests.

It is possible that is not taking into account my apikey and is using the default api key and i'm getting a throttle error or something like that?

More info:

this works ok (and is fast):
const provider = new ethers.providers.EtherscanProvider('ropsten', mi-api-key);

this fails randomly (and is slow):

const provider = ethers.getDefaultProvider('ropsten'
    , {
        etherscan: mi-api-key
    }
);

It seems defaultprovider is not taking into account the api keys.

Ran into the same issue reading getEthToTokenInputPrice from Uniswap v1 contracts. Switching away from getDefaultProvider as described above fixed.

I also have same problem with FallbackProvider but I set quorum to 1 so it should not be a problem, not sure how to create a stable reproduce steps...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricmoo picture ricmoo  ·  24Comments

MicahZoltu picture MicahZoltu  ·  24Comments

fmsouza picture fmsouza  ·  44Comments

bpierre picture bpierre  ·  43Comments

gitpusha picture gitpusha  ·  25Comments