hswick / exw3

High level Ethereum RPC Client for Elixir
Apache License 2.0
151 stars 45 forks source link

Calling function that requires bytes argument fails #139

Open cjimison opened 2 years ago

cjimison commented 2 years ago

I have been running into a case where if I use ExW3 with a solidity smart contract that needs a bytes function argument it will fail. I think this might be related to how the encoding works within ExW3, however when I bypass ExW3 and use ABI directly it works:

ABI.encode("setTest(bytes)", [encoded_data])

From what I can tell, there seems to be an extra 64 bytes of data being included in the ExW3 version that I am not sure where it is coming from.

Example:


# Fails when submitted as part of the transaction

# the variable `abi` was parsed from the contract abi file using ExW3
ExW3.Abi.encode_method_call(abi, "setTest", [<<1,2,3,4>>])
"0af724830000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040102030400000000000000000000000000000000000000000000000000000000"

# Works when submitted as part of the transaction

ABI.encode("setTest(bytes)", [<<1,2,3,4>>]) |> Base.encode16(case: :lower)
"0af72483000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040102030400000000000000000000000000000000000000000000000000000000"

Looking at the output it seems to be include a second "0x2" block of 64 bytes so I think something is getting wrapped twice.