简体   繁体   English

从Web3向固定合同方法发送值会导致“无效的元组值”错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM