当前位置:网站首页>简单科普Ethereum的Transaction Input Data
简单科普Ethereum的Transaction Input Data
2022-06-26 15:29:00 【NFT践行者】
这里跟大家分享一下十六进制数据调用合约背后的原理,希望对大家有所帮助。
Transaction主要字段
大家知道每次和以太坊网络交互,不管是直接转账还是调用合约其实都是向以太坊网络发起了一笔Transaction,这个Transaction通过Metamask签名并发送至以太坊节点后,以太坊的矿工就会执行这笔transaction。
Transaction中有以下几个比较重要的字段:
- from:代表谁发起的这笔Transaction,一般是你的钱包地址
- to:向谁发送。如果是转账,to就是你要转账的目标钱包地址;如果这笔交易是调用合约,to就是要调用的合约地址
- value:发送多少ETH
- Input Data:输入数据。如果是转账,Input Data就是0x为空,不用传入,因为“from”、“to”和“value”字段已经可以确定这笔交易由“谁”,转“多少ETH”,到“谁”去了;但如果这笔交易是调用合约,Input Data中就需要包括你所需要调用合约所需的所有信息,例如合约方法、参数(上述截图中的十六进制数据,所输入的其实就是Input Data)
以这笔WomenUniteNFT的Mint交易为例,tx=0x64c55a520934460ef87a1bd5f0e86c837babae86897ddf285ae4dc2feafa166d, 可以看到from是mint这哥们的钱包,to是WomenUniteNFT合约地址,value是0,代表没花钱(但有gas),data就是他传入的十六进制的数据。
Input Data解析
还是以上面这笔交易的Input Data “0xa0712d6800000000000000000000000000000000000000000000000000000000000000fa”为例。
方法标识
首先合约中有漏洞的方法是“def mint(uint256 _wad) payable:”,用keccak256算出”mint(uint256)”的哈希值的十六进制,同时取前八位就能得到Input Data的方法名标识“a0712d68”了。(注意计算的哈希只需要是函数名+参数类型)
方法参数
方法标识确认之后,就需要传入mint数量,如果需要一次mint 250个,那传入250的十六进制“fa”。
上述mint方法中的参数是uint256类型的,在拼入参的时候需要占用对应位数,uint256类型的参数如果换成16进制的话总共需要64位,所以将“fa”补0到64位即为“00000000000000000000000000000000000000000000000000000000000000fa”。
拼凑得到Input Data
这时与之前算好的方法名标识“a0712d68”拼一块,就可以得到“a0712d6800000000000000000000000000000000000000000000000000000000000000fa”的Input Data数据了,与上面Mint的这笔交易的Input Data相同。(如果有多个参数,按照参数类型的长度接着后面继续拼就行)
将此Input Data数据在Metamask给合约地址转账时输入,以太坊矿工节点就知道执行该合约的哪个方法以及传入什么样参数了。
最后
大家如果还是不太理解的话,就在Etherscan上多对比下合约以及transaction的InputData,实际上都可以自己算出来。
以上内容不作任何投资建议,投资有风险!
边栏推荐
- 【TcaplusDB知识库】TcaplusDB系统用户组介绍
- 反射修改final
- How to configure and use the new single line lidar
- 【leetcode】112. Path sum - 113 Path sum II
- [CEPH] cephfs internal implementation (I): Concept -- undigested
- Shell script multi process concurrent writing method example (high level cultivation)
- nanoPi Duo2连接wifi
- Is it safe to open a stock account through the account opening link of the broker manager? Or is it safe to open an account in a securities company?
- 【ceph】mkdir|mksnap流程源码分析|锁状态切换实例
- golang 1.18 go work 使用
猜你喜欢
Super double efficiency! Pycharm ten tips
【ceph】CEPHFS 内部实现(一):概念篇--未消化
How to handle 2gcsv files that cannot be opened? Use byzer
2Gcsv文件打不开怎么处理,使用byzer工具
【TcaplusDB知识库】TcaplusDB单据受理-事务执行介绍
[tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
AbortController的使用
【ceph】cephfs的锁 笔记
【TcaplusDB知识库】TcaplusDB数据构造介绍
HW安全响应
随机推荐
音视频学习(一)——PTZ控制原理
在哪个平台买股票开户安全?求指导
1. accounting basis -- several major elements of accounting (general accounting theory, accounting subjects and accounts)
A blog to thoroughly master the theory and practice of particle filter (PF) (matlab version)
【毕业季·进击的技术er】 什么是微信小程序,带你推开小程序的大门
Applicable and inapplicable scenarios of mongodb series
2Gcsv文件打不开怎么处理,使用byzer工具
【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
Beijing Fangshan District specialized special new small giant enterprise recognition conditions, with a subsidy of 500000 yuan
Is it safe to open a stock account through the account opening link of the broker manager? Or is it safe to open an account in a securities company?
【ceph】CephFS 内部实现(二):示例--未消化
Particle filter PF -- Application in maneuvering target tracking (particle filter vs extended Kalman filter)
Mongodb series window environment deployment configuration
El dialog drag and drop, the boundary problem is completely corrected, and the bug of the online version is fixed
/etc/profile、/etc/bashrc、~/. Bashrc differences
Analysis of ble packet capturing debugging information
One click analysis hardware /io/ national network performance script (strong push)
评价——模糊综合评价
[problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long
[tcapulusdb knowledge base] tcapulusdb system user group introduction