esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum
Apache License 2.0
76 stars 20 forks source link

Encode abi params #39

Closed tomasz90 closed 2 years ago

tomasz90 commented 2 years ago

Hi again :)

Is there possibility to encode abi params without function name itself? My workaround is empting first 4 bytes for example:

val args = Tuple(Address.wrap("0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32"), 5)
val f = Function("(address,uint8)")
val callData = f.encodeCall(args)

it gives: 0xd6ec702b0000000000000000000000005757371414417b8c6caad45baef941abc7d3ab320000000000000000000000000000000000000000000000000000000000000005 then I clear first bytes. I bet that this library have such functionality.

Thanks!

esaulpaugh commented 2 years ago

Yes if you have a TupleType reference you can call the encode method.

If you have a Function you can call getInputs to get the params TupleType

You can also use TupleType::parse or TypeFactory::create giving the signature of the params type.

For example passing the String "(int,bool,string)" would create a TupleType with three elements.