I have a solidity function which looks like this-
function issueCertificate(address _recipient, bytes32 _certi_name)
When I call the function using truffle console, I am able to run it using-
issueCertificate("0x0213e3852b8afeb08929a0f448f2f693b0fc3ebe", "random")
But when I run it using web3 and forms with same data in string format, it gives error-
Error: Given parameter is not bytes: "random"
I have a solidity function which looks like this-
function issueCertificate(address _recipient, bytes32 _certi_name)
When I call the function using truffle console, I am able to run it using-
issueCertificate("0x0213e3852b8afeb08929a0f448f2f693b0fc3ebe", "random")
But when I run it using web3 and forms with same data in string format, it gives error-
Share Improve this question edited Jul 6, 2022 at 14:28 TylerH 21.1k78 gold badges79 silver badges113 bronze badges asked Sep 29, 2017 at 14:34 Shubham ChaudharyShubham Chaudhary 1,4824 gold badges20 silver badges38 bronze badgesError: Given parameter is not bytes: "random"
2 Answers
Reset to default 3If you're using web3.js version 1.0, you can wrap the string as shown here:
web3.utils.asciiToHex("random")
See the documentation here:
https://web3js.readthedocs.io/en/1.0/web3-utils.html#asciitohex
Try:
issueCertificate("0x0213e3852b8afeb08929a0f448f2f693b0fc3ebe", bytes32("random"))
Basically, wrap the string with bytes32()
Edit, missed the call being made from Web3 try:
issueCertificate("0x0213e3852b8afeb08929a0f448f2f693b0fc3ebe", web3.fromAscii("random"))
Basically, in Web3 wrap the string with web3.fromAscii()
Update:
Latest version uses:
issueCertificate("0x0213e3852b8afeb08929a0f448f2f693b0fc3ebe", web3.utils.fromAscii("random"))