def decode_function_calldata(self, calldata: HexStr) -> Optional[tuple]
# 解码函数调用数据
calldata = "0xa9059cbb000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b0000000000000000000000000000000000000000000000000de0b6b3a7640000"
result = contract.decode_function_calldata(calldata)
if result:
function_name, parameters = result
print(f"Function Name: {function_name}")
print(f"Parameters: {parameters}")
# 编码后解码验证
encoded = contract.encode_function_calldata(
"transfer",
"0xab5801a7d398351b8be11c439e05c5b3259aec9b",
Web3.to_wei(1, 'ether')
)
if encoded:
decoded = contract.decode_function_calldata(encoded)
print(f"Decoded: {decoded}")