1

The Solidity example code :

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract Test {
  uint256 testvalue;

  function testFunc(uint amount) public returns(uint) {
    testvalue = testvalue + amount;
    return testvalue; // read return data
  }
}

etherjs example code :

const TEST = await ethers.getContractAt("Test",address)

const tx = await TEST.testFunc(5);
const result_tx = await tx.wait()

The testFunc function has a return. But there is no value for return on successfully completed transaction with ethers. Is it like that?

1 Answer 1

2

see this related question: https://stackoverflow.com/questions/71254497/documentation-for-ethers-getcontractat#:~:text=The%20getContractAt()%20function%20is,not%20included%20in%20their%20documentation.

This is a hardhat ethers only extension, looks like you need to provide a signer or its a read-only contract. Since your function attempts to mutate testvalue, my guess is that it will not be a successful transaction.

https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-ethers#helpers

Your Answer

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

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