Here is the code I used to call setValue and getValue in contract Hello.sol deployed with etherjs 5.0:

  import { ContractFactory, ethers } from "ethers";

  let contract_at_address = new ethers.Contract(contract.address, abi, signer); //<<==contract.address is the deployed address. abi and signer were defined earlier.
  await contract_at_address.setValue(10); //<<setter
  let value = await contract_at_address.getValue(); //<<==value shall be 10
  console.log("value contract at address : ", value)

But it throws error:

[Sun Nov 15 2020 23:10:11.457]  WARN     Possible Unhandled Promise Rejection (id: 0):
Error: call revert exception (method="getValue()", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.5)
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

I am following the doc for contract. The same functions are tested in truffle/ganache and they all work fine. What's missing here to call setter (change state) and getter (view only) functions in ethersjs?

UPDATE: Hello.sol

pragma solidity 0.7.0;

contract Hello {
    address owner;
    uint256 value;
    event initContract(address _owner);
    constructor() {
        owner = msg.sender;
        emit initContract(owner);
    function setValue(uint256 _value) public {
        value = _value;
    function getValue() view public returns (uint256) {
        return value;
  • Are you sure that function getValue is constant (pure or view)? The errorSignature=null error implies that ethers.js is trying to execute it as a transaction (rather than as an RPC). Nov 16, 2020 at 7:58
  • it is view function. Updated is the Hello.sol.
    – user938363
    Nov 16, 2020 at 16:05
  • There are 2 ways to call function in contract doc. One is hello.getValue() and another is hello.functions.getValue(). I don't quite understand the difference but both of format throw error.
    – user938363
    Nov 16, 2020 at 16:48
  • The problem is that it was missing await in contract deployment. Contract deploy is an async operation and needs to await contract.deployTransaxtion.wait() before calling the functions in contract.
    – user938363
    Nov 17, 2020 at 22:24

1 Answer 1


Try out the following,

// Set Provider
const rpc = 'YOUR RPC';
const provider = new ethers.providers.JsonRpcProvider(rpc);

// Contract Instance
const contractInstance = new ethers.Contract(contractAddress, contractABI, provider);

// For view function
var result = await contractInstance.getValue();

Hope it helps!

  • 1
    const contractInstance = await ethers.getContractAt("contracts/XYZ.sol:ContractName", contractAddress);
    – Russo
    Sep 14, 2022 at 11:09

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.