[英]Sending value to a solidity contract method from web3 results in `Invalid Tuple Value` error
I'm sending values to a solidity 0.5.1
method using web3
and keep getting an invalid Tuple value
error. 我正在使用
web3
将值发送到web3
solidity 0.5.1
方法,并不断收到invalid Tuple value
错误。
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
: 我从
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
. 我尝试发送一个
string
,一个number
并将该字符串转换为hex
。 The same error: invalid tuple value
. 相同的错误:
invalid tuple value
。 What am I missing? 我想念什么?
EDIT: You are instantiating new struct wrong. 编辑:您正在实例化新的结构错误。 Problem is the contract.
问题是合同。 See the correct way
看到正确的方法
function creatMyStruct(bytes32 _id, string memory _str) public
{
mystruct storage newStruct = mystruct({id: _id, str: _str});
structs[id] = newStruct;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.