1

I looked everywhere for people with similar problems, but I couldn't find anything.

I am confused why I keep getting this error (yes, I know others have had this error too, but not for the same reason as I):

>Error: invalid bytes32 value (arg="_orgName", coderType="bytes32", value="0x7b22436f6e74656e742d54797065223a226170706c69636174696f6e2f782d7777772d666f726d2d75726c656e636f646564222c224e616d65223a22546573742075736572227d")

1) The information the node server is passing to the contract is a payload from a webpage.

2) Essentially here is what is happening:

  • Node takes form payload which is a json object and converts it into hex

  • Send hex to the contract with the 3 fields orgName,helloId,fctChain.

I know I am passing in the right data, but I keep getting an error return. When i did a typeof convertToHex i got a string.

Any guidance is helpful.

Thank you,

Here's what my code looks like:

function sendToContract(req, res, next) {

  let convertToHex = web3.utils.toHex(JSON.stringify(req.body));

  ACF.methods.registerNewAsset(convertToHex, convertToHex, fctAddress).send()
    .then(results => {
      res.send(results)
    })
    .catch(err => {
      // console.log(err)
    })
  res.send(results);
}

Here's what the contract looks like:

function registerNewAsset(bytes32 _orgName, uint _hellId, bytes32 _fctChain) external onlyOwner {

        NewAsset storage asset = hercIdToAsset[_hercId];

        asset.orgName = _orgName;
        asset.helloId = _helloId;
        asset.fctChain = _fctChain;

        addressToAssetArray[msg.sender].push(asset);

    }

My goal was to implement the send transaction based on this documentation: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-send

I'm using web3js + node + solidity.

  • I suggest that you console.log(JSON.stringify(req.body)) and see what exactly it is that you're trying to convert to hex. – goodvibration Nov 29 '18 at 9:12
  • @goodvibration i was converting the entire form payload into hex. turns out i only needed 3 portions of it, so now i am reassigning the variables to specific portion of the payload and converting that into hex and then pushing it out to the smart contract, however, i am not sure if that will work. – newFinancier Nov 29 '18 at 21:11
0

IMO, there are ample things wrong in code.

let convertToHex = web3.utils.toHex(JSON.stringify(req.body));

In this line, you are trying to convert complete request body in hex not a property of it, which doesn't seem a desired behaviour.

function registerNewAsset(bytes32 _orgName, uint _hellId, bytes32 _fctChain)

Apart from this, in this line, you second parameter is uint but you are sending same hex (i.e. convertToHex) for _helloId.

Also, from the name of third parameter(i.e. fctAddress), it seems that you are passing an address to bytes32 type variable _fctChain.

I think, rectifying each of them will get it working.

| improve this answer | |

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.