0

I'm sending values to a solidity 0.5.1 method using web3 and keep getting an invalid Tuple value error.

Here's the relevant contract code:

struct mystruct {
    bytes32 id; 
    string str;
}

mapping (bytes32 => mystruct) structs;

function creatMyStruct(bytes32 id, string memory str) public {
    mystruct memory newStruct = mystruct(id, str);
    structs[id] = newStruct;
}

I'm calling this from node.js:

contract.methods.creatMyStruct(someId, someString).send({from: fromAccount, gas: gasEstimate})
    .then(receipt => {
       var txhash = receipt.transactionHash;
       resolve(txhash);
    },
    (error) => {
        reject(error);
    }).catch((err) => {
         reject(err);
    });

I tried sending a string, a number, and converting the string to hex. The same error: invalid tuple value. What am I missing?

EDIT: here are some of the values I tried for id, which is the one that causes the problem. The string values below were tried when the id value was defined as a string in the contract, and the numeric ones when it was defined as bytes32. I can use both, so a solution for either one would be great.

let id = '123'; 
id = "hello"; 
id = '0xabca00000000000000000000000000';
id = 0xabca00000000000000000000000000;
id = 1;
id = 12300000000000000000000000000000;
id = 'hello';

I tried both as is, or by converting to hex:

userId = web3.utils.asciiToHex(userId);

The same error is generated for all of them. Here's a bit more description in the error:

reason: 'invalid tuple value',
code: 'INVALID_ARGUMENT',
coderType: 'tuple',
value: '0x68656c6c6f' 
  • The error implies that the problem is either with the value of someId or the value of someString or both. Your question implies that you under that. However, you have not included either one of them here; are we supposed to guess what they are or how you initialize them??? – goodvibration Jul 29 at 18:16
  • @goodvibration I added some of the values I tried. – Eddy Jul 29 at 19:01
  • I went back to compiler version 0.4.24. Problem gone. – Eddy Jul 30 at 8:50
0

As you define the input parameter to be bytes32, the function expects a specific length of bytes to be valid. You would need to pad your input to 32 bytes.

E.g. id = '0xabca00000000000000000000000000'; shall be id = '0xabca000000000000000000000000000000000000000000000000000000000000';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.