0
async function viewmyactivedeposits() {
  const result = await myLoanContract.methods
    .viewMyActiveDeposits()
    .call()
    .then(function (result) {
      let data = Array.from(result);
      $("#viewdepositid").html(
        "<br> My active deposit ID's are  : " + JSON.stringify(data)
      );
      console.log(result);
    })
    .catch((err) => {
      console.log("error :::::", err);
    });
}

I have been trying to access a smart contract method that returns multiple values and pass it into a javascript function. But the result is showing out as an empty array.

I have already checked the smart contract from the backend on remix and it is working perfectly fine there and returning the requisite values. Does anybody have any idea why this is happening? Any help will be greatly appreciated.

1 Answer 1

0

Have you added the abi for calling the smart contract? I think adding this line should fix your problem.

const myLoanContract = new web3.eth.Contract(myLoanContractAbi, myLoanContractAddress)

myLoanContractAbi -> Get the abi from remix and myLoanContractAddress -> Get the smart contract address from chain where you've deployed.

So your function should be,

  const myLoanContract = new web3.eth.Contract(myLoanContractAbi, myLoanContractAddress)
  const result = await myLoanContract.methods
    .viewMyActiveDeposits()
    .call()
    .then(function (result) {
      let data = Array.from(result);
      $("#viewdepositid").html(
        "<br> My active deposit ID's are  : " + JSON.stringify(data)
      );
      console.log(result);
    })
    .catch((err) => {
      console.log("error :::::", err);
    });
}```
1
  • Already did that in lines before it,.. the other functions which are returning single values are working fine, only two functions returnig multiple values are creating problems
    – Tanmay
    Commented Aug 9, 2022 at 8:37

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.