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.
console.log(JSON.stringify(req.body))
and see what exactly it is that you're trying to convert to hex.