Unable to read the return value of a non "view" on-chain function

23 Views Asked by At

I'm tring to adapt to Ethers 6.11 an example I found about decoding the return values of a non "view" on-chain function (Ethereum smart-contracts). I'm referring to the first answer in this page: https://ethereum.stackexchange.com/questions/88119/i-see-no-way-to-obtain-the-return-value-of-a-non-view-function-ethers-js Their solution is:

  const txResult = await provider.call({
    to: sumOfTokens.address,
    data: txData
  });
  const decodedResult = ethers.utils.defaultAbiCoder.decode("uint256", txResult);

Ethers 6.11 will throw errors due to updated libraries.

I'm trying the following, but still unsuccessfully.

   const txResult = await myProvider.call({
     to: MY_CONTRACT_ADDR,
     data: txData
   });

   const decodedResult = defaultAbiCoder.decode("string", txResult);
   console.log(decodedResult)

I'm receiving the error:

TypeError: Cannot read properties of undefined (reading 'decode')

What am I doing wrong?

0

There are 0 best solutions below