web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

How to ABI decode given just signature

Open fxfactorial opened this issue 2 years ago • 0 comments

What piece of the framework are having the lack of docs?

Here is a code sample

let payload = "128acb08000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000fffd8963efd1fc6a506488495d951d5263988d2500000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb8a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000"

let sig = "swap(address,bool,int256,uint160,bytes)"
// actually does work on payload if you remove the first four bytes of payload
let result = ABIDecoder.decode(types: [
                                 .address, .bool, .int(bits:256), .uint(bits:160), .dynamicBytes,
                               ],
                               data: Data(hex: payload[8...]))

now how can I get result without having to manually give the types? that is, I want to pass to ABIDecoder just the (address,bool,int256,uint160,bytes) and data and get the parsed result.

What bit of docs would you like to have?

How to decode using just signature

fxfactorial avatar Nov 02 '23 19:11 fxfactorial