I have a solidity function

 function foo (bytes memory myBytes) {}

In javascript I have an array:

  let myArray =  [ '0xAA', '0x1', '0x55']

If I copy and paste the array into remix, my foo function works fine. My question is how do I call the function from javascript from truffle?

let tx = await contract.foo(myArray)


However if I pass a string version it works fine:

let tx = await contract.foo("0xAA155")

Is there any way to make it work without converting to a string? If I have to convert to a string, whats the best way to do it?

  • What is the error that you are getting? Remember Solidity is statically typed and JS is not. Looks like Truffle wants bytes and you are giving it an array. – valem Feb 25 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.