1

When calling a Smart Contract method that requires a bytes parameter, truffle is not accepting the bytes parameter, no matter how I express it. All these tests fail on truffle:

// 0x6154696d657374616d704576656e744369706865726564 is hex for string 'aTimestampEventCiphered'
let bytecode = myMethod(..., 0x6154696d657374616d704576656e744369706865726564).encodeABI();
let bytecode = myMethod(..., web3.fromUtf8("aTimestampEventCiphered")).encodeABI();
let bytecode = myMethod(..., "aTimestampEventCiphered").encodeABI();
let bytecode = myMethod(..., "0x6154696d657374616d704576656e744369706865726564").encodeABI();
let bytecode = myMethod(..., bytes("aTimestampEventCiphered")).encodeABI();
let bytecode = myMethod(..., web3.fromAscii("aTimestampEventCiphered")).encodeABI();

Truffle is throwing this error on and on:

Error: invalid bytes value (arg="_timestampEventCiphered", coderType="bytes", value=9.322336429922961e+54)

Any idea how to properly send a bytes argument from truffle? Thx!

  • 1
    If you're using Truffle 4.1.14 or earlier, which I know for sure to rely on web3 v0.x, then the last line should work. – goodvibration Dec 26 '18 at 9:47
  • 1
    If you're using a later version of Truffle, which has possibly switched to web3 v1.x (I sure as hell hope not, because that would yield a ton of changes in my testing infrastructure), then replace web3.fromAscii with web3.utils.asciiToHex. – goodvibration Dec 26 '18 at 9:49
  • 1
    I've used Truffle and it accepts strings in hexadecimal with 0x prefix as bytes array, like this let bytecode = myMethod(..., "0x6154696d657374616d704576656e744369706865726564") . Likely you have another error. – Ismael Dec 26 '18 at 14:44
  • This "0x6154696d657374616d704576656e744369706865726564" is a string in itself and throws same error: invalid bytes value... – Juan Ignacio Pérez Sacristán Dec 26 '18 at 16:54
  • 1
    @JuanIgnacioPérezSacristán I've tried with both truffle v4 an v5 and both accept "0x11223344" as a bytes array. What is your solidity function like? and How are you making the call to the contract? I can execute from the console without issues m.foo(web3.utils.toHex("hola")) or m.foo('0x686f6c6101'). Javascript is quite lax on types types so it should not complain about string, perhaps are you using typescript or other language? – Ismael Dec 27 '18 at 3:29

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.