0

I have been developing with Hardhat without problem. When I deploy my smart contracts to a test network (Ropsten or Rinkeby), none of my view methods work. For example:

function testView() public virtual view returns(bool) {
    return true;
  }

This function will always revert on all test networks, even though my transaction functions work just fine. The revert exception is:

An unexpected error occurred:

Error: call revert exception (method="testView()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.4.1)
    at Logger.makeError (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at Interface.decodeFunctionResult (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/abi/src.ts/interface.ts:425:23)
    at Contract.<anonymous> (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/src.ts/index.ts:332:44)
    at step (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/lib/index.js:48:23)
    at Object.next (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/lib/index.js:29:53)
    at fulfilled (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/lib/index.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  reason: null,
  code: 'CALL_EXCEPTION',
  method: 'testView()',
  errorArgs: null,
  errorName: null,
  errorSignature: null,
  address: '0x27AbaB051007f7325ac2246187DD92b513B26d39',
  args: [ ],
  transaction: {
    data: '0x24d7806c000000000000000000000000809e2b319e4d398f9282167271ed2f69d63ef6be',
    to: '0x27AbaB051007f7325ac2246187DD92b513B26d39',
    gasLimit: BigNumber { _hex: '0x05f5e100', _isBigNumber: true },
    from: 'xxxxxx'
  }
}

AFAICT, this may be related to a similar error, where transactions require a gasLimit. If I try to run certain transactions upon deploying, the first time (only) I receive:

Error: cannot estimate gas; transaction may fail or may require manual gas limit

Adding a { gasLimit } does indeed fix that problem.

2
  • 1
    How do you call testView() function? (Can you post your code?) Did you try calling the function from Etherscan's API? Oct 22 '21 at 7:13
  • you are sending a transaction to a view method. you need just to call it (it is only a read function and don't need tx). by the way, methods that don't change data and don't even read data from storage should be pure
    – Majd TL
    Oct 22 '21 at 14:27
0

This GitHub issue on ethersjs insists that my error was due to using the "wrong network," and indeed that was the problem. Specifically, I had misconfigured my deployment files such that Ropsten and Rinkeby were saved inverted, such that each was using the contract addresses from the other.

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.