admin管理员组文章数量:1333442
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"))
本文标签: javascriptString parameter not automatically parsing into bytes32 when used with formStack Overflow
版权声明:本文标题:javascript - String parameter not automatically parsing into bytes32 when used with form - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742354235a2459098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论