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'
someId
or the value ofsomeString
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 '19 at 18:16