1

I am getting this error when I try to access a string from a dynamic array

call revert exception; VM Exception while processing transaction: reverted with panic code 50 [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="getTasks(uint256)", data="0x4e487b710000000000000000000000000000000000000000000000000000000000000032", errorArgs=[{"type":"BigNumber","hex":"0x32"}], errorName="Panic", errorSignature="Panic(uint256)", reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)

This is the code I wrote in the client side

const fetchTasks = async () => {
    try {
      const prov = await getProviderOrSigner();
      const contract = await contractInstance(prov);
      const query = await contract.getTasks(1);
      console.log(query);
    } catch (error) {
      console.error("Query failed", error.message);
    }
};

This is the smart contract I try to read

function getTasks(uint i) external view returns (string memory) {
        return users[msg.sender].tasks[i];
}

The interesting thing is that getTasks() function works properly in Remix. When I put 1 as an argument there, it returns the string but somehow, I cannot return from the client side

2 Answers 2

1

It looks like you are trying to access an array index that does not exist, probably because the tasks array for that msg.sender is empty. Check that the address you are calling from on client side is the same as the address you are using in Remix.

3
  • I am sure it is the same address Aug 8, 2023 at 20:45
  • Ok, so what environment are you calling to? Is it real or a local fork? Is it the same for the client and Remix?
    – ceseshi
    Aug 8, 2023 at 21:26
  • I wrote two missions on Sepolia and trying to fetch them. When I load the contract from address in Remix to test the function, it works fine. Also, I wrote those missions to blockchain through client side, so I do not think it is an environmental issue. @ceseshi Aug 9, 2023 at 4:00
0

I solved the issue using an address parameter in the function instead of msg.sender. It seem that msg.sender does not applicable to the frontend

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.