javascript - String parameter not automatically parsing into bytes32 when used with form - Stack Overflow

I have a solidity function which looks like this-function issueCertificate(address _recipient, bytes32

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-

Error: Given parameter is not bytes: "random"

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

If 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"))

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742354236a4428121.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信