简体   繁体   中英

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.

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: 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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