ethers.js: CALL_EXCEPTION on array getter

maybe i’m missing something here, but i cannot call an array getter successfully with an index different from 0.

my code:

const swap = new Contract(pool.curve.address, curvefi.curveAbi, provider);
console.log(await swap.coins(0)); // works ok
console.log(await swap.coins(1)); // Error: call revert exception (method="coins(int128)", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.5)

getter abi:

{
 "name": "coins",
 "outputs": [
  {
   "type": "address",
   "name": "out"
  }
 ],
 "inputs": [
  {
   "type": "int128",
   "name": "arg0"
  }
 ],
 "constant": true,
 "payable": false,
 "type": "function",
 "gas": 2040
}

contract: https://etherscan.io/dapp/0x45f783cce6b7ff23b2ab2d70e416cdb7d6055f51#readContract

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@cruzdanilo , I got my ABI from etherscan. If I remove gas from the abi, my example works too. ethers uses the abi gas when provided.

From my testing, different node gives different error when a low gas amount is provided.

  • infura: call revert exception (method=“coins(int128)”, errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.5

  • alchemy and Cloudflare {“jsonrpc”:“2.0”,“id”:42,“error”:{“code”:-32000,“message”:“out of gas”}}

  • etherscan sometimes works sometimes timeout Error: timeout

Actually. This might be something I need to address in ethers.

I currently add 21000 gas to the gas cost in the ABI, but I should compute the intrinsic gas cost of sending the data in the transaction. i.e. the cost of sending a byte in data that is 0, is cheaper than the cost of sending non-zero. So the 1 costs more. Ethers can account for this. It just isn’t now.

Vyper is much more accurate when estimating gas costs, which is why it’s on the edge and this hasn’t come up before.

I’ll look into this soon.