Consensys / abi-decoder

Nodejs and Javascript library for decoding data params and events from ethereum transactions
GNU General Public License v3.0
633 stars 218 forks source link

decoding abi #85

Open GildedHonour opened 2 years ago

GildedHonour commented 2 years ago

In README:

Need to pass the ABI's manually to the library in order to be able to decode params later

//Add ABI's

const testABI = [{"inputs": [{"type": ....}];
abiDecoder.addABI(testABI);

//Decode Tx data

const testData = "0x53d9d910000........0000a6d9c5f7d4de3cef51ad3b7235d79ccc95114daa";
const decodedData = abiDecoder.decodeMethod(testData);

1) What's testData? Is it transaction.input? Or what is it?

2) abiDecoder.addABI(testABI); - does this mean that once I've added some abi (abi1), the method decodeMethod will ONLY be able to decode methods using once specified abi1? What if I have multiple abi-s and multiple methods to decode? In other words, how can I decode a specifi method with a specific abi?

Yiwen-Gao commented 1 year ago

What's testData? Is it transaction.input? Or what is it?

Yep, I believe testData is the transaction's input and includes the function signature in the first eight bytes.

abiDecoder.addABI(testABI); - does this mean that once I've added some abi (abi1), the method decodeMethod will ONLY be able to decode methods using once specified abi1? What if I have multiple abi-s and multiple methods to decode? In other words, how can I decode a specifi method with a specific abi?

I think you can call addABI multiple times. As long as the function signatures are unique, it'll add a new entry to the state and not overwrite an existing one (see L35 and L37 below). https://github.com/ConsenSys/abi-decoder/blob/a9ed4923433ad32069e2ea963d683ed2ff49fa07/index.js#L20-L46