如何读取以太坊区块交易:包含bytes[]字段的数据字段

发布于 2025-01-16 22:56:37 字数 4101 浏览 0 评论 0 原文

是否可以通过查看以太坊区块交易 data 字段来解码诸如 multicall(uint256 Deadline, bytes[] data) 之类的输入数据?

给定的以太坊交易可能包含一个数据字段,例如:

{
    "hash":"0x688c0f7e7ad5c59e4c3e24199e8e56753b95960324e3bb41da210eb0416e581d",
    "nonce":"0x73",
    "blockHash":"0x33fbe975a5a9c6a399c55f1bcb8130cd1d0c560722483dcd72d964020f156f7d",
    "blockNumber":"0xdc0ba9",
    "transactionIndex":"0xde",
    "from":"0xfcf9c19841cd8c6cd7114e638b02e62189a89601",
    "to":"0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
    "value":"0x0",
    "gasPrice":"0x4190ab000",
    "gas":"0x6621f",
    "data":"0x5ae401dc000000000000000000000000000000000000000000000000000000006236a988000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000001edd40a09ca2037a8ce4000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fc09c7cfd9c175dd9423ca02ae1249579ab12f12000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000fcf9c19841cd8c6cd7114e638b02e62189a8960100000000000000000000000000000000000000000000000000000000",
    "input":"0x5ae401dc000000000000000000000000000000000000000000000000000000006236a988000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000001edd40a09ca2037a8ce4000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fc09c7cfd9c175dd9423ca02ae1249579ab12f12000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000fcf9c19841cd8c6cd7114e638b02e62189a8960100000000000000000000000000000000000000000000000000000000",
    "type":"0x0",
    "v":"0x26",
    "s":"0x3397f6969aec9a7d1c168765985d9ff51d9b1bb4a84126ce561e1793bcc82af7",
    "r":"0xd692324d08b4ed25a2b7a37cc247b4f879d0e3bcb3d851fdc087f3ad40579edb"
}

根据此 etherscan 记录,上述块是发送到Uniswap V3:路由器 2。我想解码 data 字段。使用 以太坊 ABI 规范,合约的 ABI 可用于查找获取智能合约中所有函数的哈希值。将函数 multicall(uint256,bytes[])5ae401dc 的 Keccak-256 哈希中的前八个字符与 data 的开头进行比较code> 上面的字段,标识函数调用。

但是,此时我无法判断上面的 bytes[] 数组指的是什么,因此无法解码 data 字段的其余部分。似乎真正解码此调用的唯一方法是梳理 uniswap 源代码,将剩余字节映射为更易于人类阅读的内容。

但不知何故,etherscan.io 设法向我们展示该交易解码为: 输入图片这里的描述

我是否遗漏了什么,或者是到达上面的转账列表以查看合同数据的唯一方法?

Is it possible to decode the input data of something like multicall(uint256 deadline, bytes[] data) by looking at the Ethereum block transaction data field?

A given ethereum transaction might contain a data field such as:

{
    "hash":"0x688c0f7e7ad5c59e4c3e24199e8e56753b95960324e3bb41da210eb0416e581d",
    "nonce":"0x73",
    "blockHash":"0x33fbe975a5a9c6a399c55f1bcb8130cd1d0c560722483dcd72d964020f156f7d",
    "blockNumber":"0xdc0ba9",
    "transactionIndex":"0xde",
    "from":"0xfcf9c19841cd8c6cd7114e638b02e62189a89601",
    "to":"0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
    "value":"0x0",
    "gasPrice":"0x4190ab000",
    "gas":"0x6621f",
    "data":"0x5ae401dc000000000000000000000000000000000000000000000000000000006236a988000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000001edd40a09ca2037a8ce4000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fc09c7cfd9c175dd9423ca02ae1249579ab12f12000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000fcf9c19841cd8c6cd7114e638b02e62189a8960100000000000000000000000000000000000000000000000000000000",
    "input":"0x5ae401dc000000000000000000000000000000000000000000000000000000006236a988000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000001edd40a09ca2037a8ce4000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fc09c7cfd9c175dd9423ca02ae1249579ab12f12000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c000000000000000000000000000000000000000000000000008e6053de0d6216000000000000000000000000fcf9c19841cd8c6cd7114e638b02e62189a8960100000000000000000000000000000000000000000000000000000000",
    "type":"0x0",
    "v":"0x26",
    "s":"0x3397f6969aec9a7d1c168765985d9ff51d9b1bb4a84126ce561e1793bcc82af7",
    "r":"0xd692324d08b4ed25a2b7a37cc247b4f879d0e3bcb3d851fdc087f3ad40579edb"
}

According to this etherscan record, the above block is a transaction sent to Uniswap V3: Router 2. I want to decode the data field. Using the Ethereum ABI Spec, the contract's ABI can be used to find get the hash of all the functions in the smart contract. Comparing the first eight characters in the Keccak-256 hash of the function multicall(uint256,bytes[]), 5ae401dc, to the beginning of the data field above, identifies the function call.

However, at this point I cannot tell what the bytes[] array above refers to, and so cannot decode the rest of the data field. It seems like the only way to really decode this call is to comb through the uniswap source code to map the remaining bytes into something more human readable.

But somehow etherscan.io manages to show us that this transaction decodes to:
enter image description here

Am I missing something, or is the only way to arrive at the list of transfers above to go through the contract data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2025-01-23 22:56:37

此 Etherscan 令牌传输列表来自交易生成的事件日志。不是直接来自 data 字段。

多重调用参数仅指定要执行内部事务的地址列表及其数据字段。

您可以在交易收据中看到事件日志列表。例如使用 web3js

const TRANSFER_EVENT_SIGNATURE = web3.utils.keccak256("Transfer(address,address,uint256)");
const txHash = "0x688c0f7e7ad5c59e4c3e24199e8e56753b95960324e3bb41da210eb0416e581d";
const txReceipt = await web3.eth.getTransactionReceipt(txHash);
for (let log of txReceipt.logs) {
    if (log.topics[0] == TRANSFER_EVENT_SIGNATURE) {
        // This is an event log of the Transfer() event
        console.log(log);
    }
}

This Etherscan token transfer list comes from event logs generated by the transaction. Not directly from the data field.

The multicall argument only specifies a list of addresses to perform internal transactions to, and their data fields.

You can see the list of event logs in the transaction receipt. For example using web3js:

const TRANSFER_EVENT_SIGNATURE = web3.utils.keccak256("Transfer(address,address,uint256)");
const txHash = "0x688c0f7e7ad5c59e4c3e24199e8e56753b95960324e3bb41da210eb0416e581d";
const txReceipt = await web3.eth.getTransactionReceipt(txHash);
for (let log of txReceipt.logs) {
    if (log.topics[0] == TRANSFER_EVENT_SIGNATURE) {
        // This is an event log of the Transfer() event
        console.log(log);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文