web3js - 如何查询 RSK 交易的内部交易?

标签 web3js rsk

如果我有 RSK 交易的交易哈希,我如何获得其内部交易 - 即智能合约何时调用其他合约的函数或进行 RBTC 转账?
我可以使用 web3.js 获取主事务,但是一旦获得它,
我无法解析它以提取发生的内部事务。
我尝试过的另一件事是使用 web3.js 查询发生交易的块,但是无法解析它以获得内部交易。

最佳答案

重申我原来的评论:

The RSK virtual machine (like the EVM) does not define "internal transaction", and hence there's no RPC to query them. You will need to "debug" the transaction execution in order to reconstruct these internals - which is quite difficult to do. Block explorers typically do this for you.


幸运的是RSK Block Explorer
公开一个 API,因此可以通过编程方式查询。
因此,虽然您将无法为此使用 web3.js,
正如你在问题中所要求的那样,
尽管如此,您仍将能够获得内部交易。
让我们举个例子,有以下事务 0x01fbd670ea2455d38e83316129765376a693852eca296b3469f18d2a8dde35d8 ,恰好有 很多的内部交易。
curl \
  -X GET \
  -H  "accept: application/json" \
  "https://backend.explorer.rsk.co/api?module=internalTransactions&action=getInternalTransactionsByTxHash&hash=0x01fbd670ea2455d38e83316129765376a693852eca296b3469f18d2a8dde35d8"
上述命令检索此特定事务的内部事务。
如果您希望为不同的交易执行此操作,
只需更改 hash 的值请求 URL 中的查询参数。
这会给你一个相当大的 JSON 响应,
我不会在这里完整复制。
然后您可以使用您的 JS 代码解析它(因为您已经在使用 web3.js)。
在命令行上,您可以使用jq 中可用的响应过滤器命令行实用程序:
curl \
  -X GET \
  -H  "accept: application/json" \
  "https://backend.explorer.rsk.co/api?module=internalTransactions&action=getInternalTransactionsByTxHash&hash=0x01fbd670ea2455d38e83316129765376a693852eca296b3469f18d2a8dde35d8" \
  | jq -c '.data[].action.callType'
以上管道输出 curl命令进入 jq那么
应用过滤器:
  • 看着data属性,并返回数组中的所有项
  • 在每个项目中深入到 action对象,并返回其 callType值(value)

  • 这导致以下输出:
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "staticcall"
    "delegatecall"
    "call"
    
    所以这个交易包含18个内部交易,
    混合 delegatecall , staticcall , 和 call ...
    确实是一个相当复杂的交易!
    现在让我们很高兴 jq命令使用不同的过滤器,
    这样我们才能获得有关最终内部交易的完整详细信息,
    这恰好是唯一的 call内部交易:
    curl \
      -X GET \
      -H  "accept: application/json" \
      "https://backend.explorer.rsk.co/api?module=internalTransactions&action=getInternalTransactionsByTxHash&hash=0x01fbd670ea2455d38e83316129765376a693852eca296b3469f18d2a8dde35d8" \
      | jq -c '.data[17].action'
    
    请注意,与上一个命令的唯一区别是现在过滤器
    .data[17].action .
    这导致以下输出:
    {
      "callType": "call",
      "from": "0x3f7ec3a190661db67c4907c839d8f1b0c18f2fc4",
      "to": "0xa288319ecb63301e21963e21ef3ca8fb720d2672",
      "gas": "0x20529",
      "input": "0xcbf83a040000000000000000000000000000000000000000000000000000000000000003425443555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000086f36650548d5c400000000000000000000000000003f7ec3a190661db67c4907c839d8f1b0c18f2fc4000000000000000000000000000000000000000000000000000000000036430c000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b0000000000000000000000000000000000000000000000000000000000000005d6328b4db96469d968348a852e6978d18b7dc9bda776727991b83f171abe4a4040ebab67dee8e9711683af91e05c3970bcb6a29502f9b35b14b7a9225d43f6e3e0cf4ae577be626ae350d8e103df88f55205167eaad7267fdbf247e4b35ec674457ac87e13451d2fa9985c854b2f84982e3b611c3b48f5045f2cdc3c6acff44d1735d2771581dc2cc7477fc846767ad088182fc317424d468477cf3a54724543000000000000000000000000000000000000000000000000000000000000000516a3d4cf7e73d17e2230c87f6ef48f38d82885c64d47fef646987f8d6fbb86405515760c786315cac84d7df048e2ba054868f2b9e2afeec0b63ebf2dcac59c8848f254382abf73cf6ce2d5134b5bc065c0706fb7a2f7886a15e79a8953ed11006c5a7d14b4fbf1bb6ff8d687a82a548dcdbd823ebec4b10e331bee332df1a7ae0e45fdac4f6648e093b90a6b56f33e31f36d4079526f871f51cafa710cdde4c3",
      "value": "0x0"
    }
    

    关于web3js - 如何查询 RSK 交易的内部交易?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68573472/

    相关文章:

    web3js - 如何使用web3 js按地址获取 token 交易列表

    ethereum - web3 getAccounts 未得到解决

    rpc - 如何从 RSKj regtest 区 block 链节点的测试账户发送 web3 交易

    solidity - 如何判断 RSK 上的智能合约是否为 NFT?

    javascript - 如何通过 Hardhat 测试 RSK 测试网部署的智能合约?

    solidity - web3 接口(interface)上的 eth.call 为返回 bytes32/string 数组的合约函数返回 null 值

    ethereum - 尝试从节点脚本部署以太坊智能合约时,为什么会出现 "invalid sender"(-32000)?

    javascript - 如何使用Web3购买ERC20代币

    javascript - 如何将 RSK 代币余额转换为 Javascript 数字?

    javascript - rsk 私钥加密 - 错误值参数应该是数字字符串