0

I have the following vyper code:

address_to_addresses: public(HashMap[address, address[2])

Vyper auto generates a view function called address_to_addresses(arg0: address, arg1: uint256) -> address that allows you to read the value of the public variable.

The abi for this function looks like this:

"name": "address_to_addresses",
"outputs": [
  {
    "type": "address",
    "name": ""
  }
],
"inputs": [
  {
    "type": "address",
    "name": "arg0"
  },
  {
    "type": "uint256",
    "name": "arg1"
  }
],
"stateMutability": "view",
"constant": true

But when I execute the following using ethersJS:

myContract.address_to_addresses(<someAddress>, 0)

I get a transaction revert error that says I have run out of gas:

Error: VM Exception while processing transaction: out of gas

How is it possible that I can be running out of gas when I am calling a view function? How can I call this function without "running out of gas"?

  • So how exactly is this question related to Solidity or web3.js? – goodvibration Sep 28 '20 at 15:35
  • While I'm not sure why it runs out of gas, view functions do have the same gas limitations as other functions. You cannot go over the block gas limit (which is about 12.5 million currently). – Morten Sep 28 '20 at 15:41
  • I am definitely not going above the gas limit of the block. I don't get this error when I run the code in truffle console using the truffle contract abstractions and the same local ganache instance. Other view function calls are working in EthersJS too. For example reading a public(uint256) works, but reading a public(HashMap[address, address[2]) fails. – Dylan Kerler Sep 28 '20 at 15:43
  • Your function is called addresss_to_addresses (triple s), but you're calling address_to_addresses (only 2 s). Is that a typo in your question, or is that the problem? – Morten Sep 28 '20 at 15:48
  • No, that is a typo in the question. Ill update it. – Dylan Kerler Sep 28 '20 at 15:48
0

It turns out this was a small issue with EthersJS.

The estimated gas is not input correctly. By manually defining the gas limit, it works:

myContract.address_to_addresses(<someAddress>, 0, { gasLimit: 60000 });

It's unclear why this is. If I set the gas limit to the actual cost of the function as defined in the abi (1654) then it fails - I have to set it to something quite large for it to work. So perhaps this is not an issue with EthersJS but an issue with truffle's abi generation being incorrect.

Since no gas is actually used in this transaction, again, i'm not sure why this is even needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.