Web3.py

decodeParameters函式python web3?

  • April 16, 2022

web3 python有沒有像“decodeParameters”這樣的功能?

在此處輸入圖像描述

問候

您可以使用 web3 py 內部使用的eth-abi模組,這是一個帶有十六進製字元串的範例:

from eth_abi import decode_abi

## Taken from tx : 0xfdc9939cb6bd71bdec1f86eccd44dc7faa79f98c82dac2ae1910e383971fbe8d
## transferFrom(address from, address to, uint256 tokenId)
## From : 0x000000000000000000000000502aef69ff64845cba427d99a29cbc05df494bc2
## To   : 0x0000000000000000000000005e3150f45f7cb0c0d424c5eee12d422c93bc0877
## TokenId : 0x00000000000000000000000000000000000000000000000000000000000002ca
DATA = bytes.fromhex("000000000000000000000000502aef69ff64845cba427d99a29cbc05df494bc20000000000000000000000005e3150f45f7cb0c0d424c5eee12d422c93bc087700000000000000000000000000000000000000000000000000000000000002ca")

## With array inputs
decodedABI = decode_abi(['address', 'address', 'uint256'], DATA)

## Tuple of result(s) : ('0x502aef69ff64845cba427d99a29cbc05df494bc2', '0x5e3150f45f7cb0c0d424c5eee12d422c93bc0877', 714)
print(decodedABI)

引用自:https://ethereum.stackexchange.com/questions/126299