String parameter not automatically parsing into bytes32 when used with form

Viewed 5835

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"

2 Answers

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