Hardhat Test – Test Returns Transaction Instead of Return Value

hardhatsoliditytruffle

I just came from truffle to hardhat.
Like the title says, I have a return value (address) of a contract and getting the transaction back. Any idea what I can do about that?

it("Check all tested", async function () {
testingFunction("createPair")

let justSo = await token.connect(actorA).approve(liqminter.address, startAmount)

const shareTokenAddress = await liqminter.connect(actorA).createPair(arg0, arg1, arg2, arg3, arg4, arg5)
console.log("Created Token: ", shareTokenAddress)

});

Output:

Created Token:  {
hash: '0xd1bd72405efb01c80b7dfe75507d93cb878ebba08bd61501dae586e938e74a88',
type: 2,
accessList: [],
blockHash: '0x044321bf6f437da19ef27f5e46e482bf58bafd823c4b8b010ff70d72dbc12498',
blockNumber: 8,
transactionIndex: 0,
confirmations: 1,
from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
gasPrice: BigNumber { _hex: '0x525b8ada', _isBigNumber: true },
maxPriorityFeePerGas: BigNumber { _hex: '0x3b9aca00', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x691c4bb4', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x01bae3d8', _isBigNumber: true },
to: '0x8ce361602B935680E8DeC218b820ff5056BeB7af',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
nonce: 3,
data:   '0xb34471f2000000000000000000000000e7f1725e7734ce288f8367e1bb143e90bb3f05120000000000000000000000000    00000000000000000000000000000000000000000000000000000000000000090f79bf6eb2c4f870365e785982e1f101e93b    9060000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000    00000000000000000000000000027100000000000000000000000000000000000000000000000056bc75e2d63100000',
r: '0x2320064cb991b41feba18c5307d11a38e1d66344e75dc9d0d6844127910e3b49',
s: '0x4253b8a878827affc6f5d08d6122ac21c28ef1f3a9227ae6025ac6a0afd1cde0',
v: 0,
creates: null,
chainId: 31337,
wait: [Function (anonymous)]
}

Best Answer

I had the same issue. It's hard to tell without seeing your contract posted, but for me, I was trying to simply read a value from a public function.

You need to let the Ethereum know that you're returning a read only value, which does not require a transaction. To do this, mark your function as a view:

function ping() public view returns (string memory) {
    return "pong";
}