0

I have a rather computationally expensive view function on my smart contract, which works with no problem on rinkeby (calling it from etherscan).

However, deploying the contract into a local chain (on ganache) and calling the function from a truffle test file, I get an out of gas error. Namely:

Error: Returned error: VM Exception while processing transaction: out of gas

Here is the code I'm using for the test:

const { assert } = require("chai")
require("chai").use(require("chai-as-promised")).should()

const MyContract = artifacts.require("./MyContract.sol");

contract("MyContract", function () {
  let contract
  before(async () => { contract = await MyContract.deployed() })

  describe('main stuffs', () => {
    it('returns SVG', async () => {
      const svg = await contract.getTOKEN(1654673700);
    })
  })
})

Is there a way to solve this issue?

I really would like to have a setup where I can test my smart contracts (even computationally expensive ones) without having to deploy to rinkeby and manually call the functions.

1 Answer 1

0

If you have a truffle-config.js like this, put in a correct amount of gas (see the gas cost on etherscan and then put a little bit more in your truffle-config.js):

rinkeby: {
    provider: ...
 
     
    **gas: 3500000,** 
     
    gasPrice: 3000000000,// 3 gwei, kovan.etherscan.io/blocks displays average is 2.5gwei 
    network_id: 4,
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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