4

In ethers.js documentation, it is written to retrieve data like below

// 'contract' is an instance of Contract made with ethers.js
// Get the current value
let currentValue = await contract.getValue();

console.log(currentValue);
// "Hello World"

But my contract returns two value from smart-contract function. below is the interface of that function

function targetNFT() external view returns(address _nftToken, uint256 _nftTokenId);

How can I retrieve multiple values returned from smart-contract using ethers.js?

1
  • 2
    It will return values as JavaScript array. Commented Jun 3, 2021 at 6:30

1 Answer 1

4
const result = await contractInstance.yourFunction();

const {0: variable_1, 1: variable_2} = result;

Reference: https://blockheroes.dev/js-read-multiple-returned-values-solidity/

Hope it helps.

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.