当前位置:网站首页>简单科普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,实际上都可以自己算出来。
以上内容不作任何投资建议,投资有风险!
边栏推荐
- [CEPH] MKDIR | mksnap process source code analysis | lock state switching example
- Seurat to h5ad summary
- 评价——模糊综合评价
- On which platform is it safe to buy shares and open an account? Ask for guidance
- Mr. Du said that the website was updated with illustrations
- Learning memory barrier
- [CEPH] cephfs internal implementation (IV): how is MDS started-- Undigested
- 有Cmake的工程交叉编译到链接时报错找不到.so动态库文件
- 5000字解析:实战化场景下的容器安全攻防之道
- 【leetcode】112. 路径总和 - 113. 路径总和 II
猜你喜欢
![[wechat applet] event binding, do you understand?](/img/83/6242e972538d0423fd4155140bb521.png)
[wechat applet] event binding, do you understand?

Notes on brushing questions (19) -- binary tree: modification and construction of binary search tree

【SNMP】snmp trap 介绍、安装、命令|Trap的发送与接收代码实现

IDEA本地代理后,无法下载插件

【毕业季·进击的技术er】 什么是微信小程序,带你推开小程序的大门

音视频学习(一)——PTZ控制原理

Application of ansible automation

Applet: uniapp solves vendor JS is too large
![[tcapulusdb knowledge base] tcapulusdb doc acceptance - transaction execution introduction](/img/7c/25a88f46e02cebd2e003b9590b9c13.png)
[tcapulusdb knowledge base] tcapulusdb doc acceptance - transaction execution introduction

Summary of students' learning career (2022)
随机推荐
/etc/profile、/etc/bashrc、~/. Bashrc differences
【ceph】cephfs caps简介
Analysis of ble packet capturing debugging information
【leetcode】48. Rotate image
Use of abortcontroller
Summary of students' learning career (2022)
[CEPH] Introduction to cephfs caps
在重新格式化时不要删除自定义换行符(Don‘t remove custom line breaks on reformat)
Golang 1.18 go work usage
[tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
sqlite加载csv文件,并做数据分析
/etc/profile、/etc/bashrc、~/.bashrc的区别
JS之手写 bind、apply、call
There are so many vulnerabilities in tcp/ip protocol?
Database - integrity constraints
【TcaplusDB知识库】TcaplusDB运维单据介绍
在校生学习生涯总结(2022)
Auto Sharding Policy will apply Data Sharding policy as it failed to apply file Sharding Policy
Is it safe to open an account for mobile stock registration? Is there any risk?
Application of ansible automation