1

I'm trying to figure out if it's possible to retrieve the return value of a non-view function. Specifically, I want to see the return value of a newly created contract

I have created a simple setup to illustrate the problem:

pragma solidity ^0.8.0;

contract TestA {

    function test() public returns (TestB) {
        return new TestB();
    }
}

contract TestB {
    uint256 public somedata = 123;
}

Is there any way to query the blockchain for the transactions return value when calling TestA::test()?

1 Answer 1

0

Ok, I was hoping to be able to read the output data from the transaction after it had been mined, but it seems like .callStatic is the closest to what I was looking for:

    const TestB = await ethers.getContractFactory('TestB');
    const TestA = await ethers.getContractFactory('TestA');
    const testA = await TestA.deploy();

    const addressTestB = await testA.callStatic.test();
    const testb = TestB.attach(addressTestB);
    await testA.test();
    console.log(await testb.somedata());

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.