分析 Raw Transanction
RLP(Recursive Length Prefix)是一种以太坊中用于序列化数据的编码方式。它被用于将各种数据结构转换为二进制格式,以便在以太坊中传输和存储。RLP 是一种递归的编码方式,允许对复杂的数据结构进行编码。所以分析交易数据就是对数据进行RLP解码
选取一个交易
获取的数据如下:
0x02f87283aa36a707843b9aca00847735940083030d40946e006ce71555b03de544f984a0ac28a72b528d52843b9aca0080c001a098abbcc6169baaa6491235d0cee189f6ca97b2f70ed5ec05b8c06780112d507da003320b01aadd5ab06e22fa52e03a70e53020e978e089a17368203ac0acbce3e5
代码解析
import rlp
from web3 import Web3## chainId
## nonce
## value
## maxFeePerGas
## gasLimit
## to
## maxPriorityFeePerGas
## v
## r
## sdata_list = []def decode(i):for j in i:if j is list:decode(j)else:if len(j) == 0:data_list.append('')else:data_list.append(j.hex())if __name__ == "__main__":raw = 'f87283aa36a707843b9aca00847735940083030d40946e006ce71555b03de544f984a0ac28a72b528d52843b9aca0080c001a098abbcc6169baaa6491235d0cee189f6ca97b2f70ed5ec05b8c06780112d507da003320b01aadd5ab06e22fa52e03a70e53020e978e089a17368203ac0acbce3e5' # 这里开头没有0x02,因为0x02是一个交易版本标识,并不参与RLP编码decode(rlp.decode(Web3.to_bytes(hexstr=raw)))print("chainId:".ljust(30), data_list[0])print("nonce:".ljust(30), data_list[1])print("value:".ljust(30), data_list[2])print("maxFeePerGas:".ljust(30), data_list[3])print("gasLimit:".ljust(30), data_list[4])print("to:".ljust(30), data_list[5])print("maxPriorityFeePerGas:".ljust(30), data_list[6])print("method1:", data_list[7])print("method2:", data_list[8])print("v:".ljust(30), data_list[9])print("r:".ljust(30), data_list[10])print("s:".ljust(30), data_list[11])
源码地址: Gitee
输出结果:
chainId: aa36a7
nonce: 07
value: 3b9aca00
maxFeePerGas: 77359400
gasLimit: 030d40
to: 6e006ce71555b03de544f984a0ac28a72b528d52
maxPriorityFeePerGas: 3b9aca00
method1:
method2:
v: 01
r: 98abbcc6169baaa6491235d0cee189f6ca97b2f70ed5ec05b8c06780112d507d
s: 03320b01aadd5ab06e22fa52e03a70e53020e978e089a17368203ac0acbce3e5
输出结果分析
Item | value | Desc | |
---|---|---|---|
👓 | ChainId | aa26a7 | 转成10进制的结果是:11151015,这个是Sepolia测试网的ChainId |
🦺 | nonce | 07 | 交易数量 |
👔 | value | 3b9aca00 | 转账金额,10进制是:1000000000(0.000000001 ETH) |
👕 | maxFeePerGas | 77359400 | 表示你愿意支付的每单位燃气的最高费率。以 Gwei 为单位,它决定了交易中每一单位燃气的费用 |
👜 | gasLimit | 030d40 | 表示你愿意为这笔交易分配的最大燃气量。燃气是以太坊中的计算资源单位,用于执行智能合约或发送以太 |
👟 | to | 6e006ce71555b03de544f984a0ac28a72b528d52 | 转入地址 |
🩰 | maxPriorityFeePerGas | 3b9aca00 | 用户愿意支付的额外费用,用于提高交易的优先级 |
💎 | v,r,s | 签名数据 |