Decode 0x3593564c execute function #4815
Replies: 6 comments 5 replies
-
Can you include the error you are getting? Also, what is the ABI used to encode the Few quick notes:
(chatted on Discord; the OP will update the issue shortly) |
Beta Was this translation helpful? Give feedback.
-
I already updated the issue. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delay. Here is a complete working example, which should help: import { ethers } from "./test.js";
(async function() {
const hash = "0xaa4eca5c9fbc195238fd2a5158e424cb899020f45dba0a8791963bded6ca4e4e";
// Connect to BNB testnet
const provider = ethers.getDefaultProvider("bnbt");
// Get the transaction from the network
const tx = await provider.getTransaction(hash);
// The minimal ABI needed for parsing
const iface = new ethers.Interface([
"function execute(bytes command, bytes[] inputs, uint deadline)"
]);
// Parse the transaction; this will include a .args property
const result = iface.parseTransaction(tx);
console.log(result);
// TransactionDescription {
// name: 'execute',
// args: Result(3) [
// '0x0b00',
// Result(2) [
// '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000',
// '0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000'
// ],
// 1724064461n
// ],
// signature: 'execute(bytes,bytes[],uint256)',
// selector: '0x3593564c',
// value: 100000000000000n
// }
const { command, inputs, deadline } = result.args;
console.log({ command, inputs, deadline });
// {
// command: '0x0b00',
// inputs: Result(2) [
// '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000',
// '0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000'
// ],
// deadline: 1724064461n
// }
})(); Let me know if anything needs further explanation. :) (I'll move this from issues to discussions) |
Beta Was this translation helpful? Give feedback.
-
I honestly don't understand what you're trying to show me. In what part of the code does parameter 2 decode? I don't see it TransactionDescription { I need to decode this parameter to obtain the wallets involved, amount of tokens sent, etc. and then send a transaction filling this parameter with new encoded data. |
Beta Was this translation helpful? Give feedback.
-
Looking at the code and documentation of PancakeSwap, I found this: Parameter 1 corresponds to the commands that will be executed in Parameter 2. In my case, 0x0b00 would be: Parameter 2 is an array of byte strings. Each element in the array is the ABI-encoded input that will be used for the respective command. Each command is identified by a byte (bytes1), and depending on the value of that byte, the corresponding input is decoded using abi.decode or Solidity assembly. The issue is that I want to decode this in Python or Node, but the results I'm getting don't make sense. With Python: This is the data I am getting. They don't make much sense. |
Beta Was this translation helpful? Give feedback.
-
Here is a short example script to decode what I think you are trying to accomplish: const Fields = {
"0b": [
"address recipient",
"uint256 amount"
],
"00": [
"address recipient",
"uint256 amountIn",
"uint256 amountOutMin",
"bytes path",
"bool payerIsUser"
],
};
function decode(command, data) {
const fields = Fields[command];
return {
command,
result: ethers.AbiCoder.defaultAbiCoder().decode(fields, data)
}
}
const commands = '0x0b00';
const params2 = [
'0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000',
'0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000'
];
for (let i = 0; i < params2.length; i++) {
const command = commands.substring(2 + (i * 2), 2 + ((i + 1) * 2));
console.log(decode(command, params2[i]));
} Which produces the following output: {
command: '0b',
result: Result(2) [
'0x0000000000000000000000000000000000000002',
100000000000000n
]
}
{
command: '00',
result: Result(5) [
'0xa9e4c77d44267F7F48f96c67faBEE55783c6e1A4',
100000000000000n,
1861818621027981n,
'0xae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee',
false
]
} Is that what you were looking for? |
Beta Was this translation helpful? Give feedback.
-
Ethers Version
6.13.2
Search Terms
abi, execute function, 0x3593564c, decode
Describe the Problem
I'm trying to decode parameter data in a swap transaction that uses function "0x3593564c execute" occurred on BSC TestNet to extract all the information they contain.
The ABI is 'function execute(bytes calldata param1, bytes[] calldata param2, uint256 param3)'.
Here is an example of the data that can be seen in the transaction details, in the Input Data field:"
https://testnet.bscscan.com/tx/0xaa4eca5c9fbc195238fd2a5158e424cb899020f45dba0a8791963bded6ca4e4e
0 | commands | bytes | 0x0b00
1 | inputs | bytes[] |
0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000
0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000
2 | deadline | uint256 | 1724064461
Param1: Commands
Param2: Unknown
Param3: Timestamp
I was searching on the internet for the param2 encoding format of this function but I couldn't find anything.
I've been trying various functions in ethers.js to decode this array of data, but none of them work without knowing its structure beforehand.
Code Snippet
No response
Contract ABI
'function execute(bytes calldata param1, bytes[] calldata param2, uint256 param3)'
Errors
No response
Environment
node.js (v12 or newer)
Environment (Other)
No response
Beta Was this translation helpful? Give feedback.
All reactions