当前位置:网站首页>Transaction input data of Ethereum

Transaction input data of Ethereum

2022-06-26 15:45:00 NFT practitioner

Here I share with you the principle behind the hexadecimal data call contract , I hope that's helpful .

Transaction The main field

You know that every time you interact with the Ethereum network , Whether it is a direct transfer or a call contract, it actually initiates a transaction to the Ethereum network Transaction, This Transaction adopt Metamask After signing and sending to the Ethereum node , Ethereum miners will carry out this transaction.

Transaction There are several important fields in :

  • from: On behalf of who initiated this Transaction, It's usually your wallet address
  • to: To whom . If it's a transfer ,to Is the address of the wallet you want to transfer money to ; If this transaction is a call contract ,to Is the contract address to be called
  • value: How much ETH
  • Input Data: input data . If it's a transfer ,Input Data Namely 0x It's empty , Don't pass in , because “from”、“to” and “value” The field has been able to determine that the transaction was made by “ who ”, turn “ How many? ETH”, To “ who ” Went to the ; But if the deal is a call contract ,Input Data You need to include all the information you need to invoke the contract , For example, the contract method 、 Parameters ( The hexadecimal data in the above screenshot , What you enter is actually Input Data)

With this WomenUniteNFT Of Mint transaction For example ,tx=0x64c55a520934460ef87a1bd5f0e86c837babae86897ddf285ae4dc2feafa166d, You can see from yes mint This guy's wallet ,to yes WomenUniteNFT Contract address ,value yes 0, It means no money ( But there are gas),data Is the hexadecimal data he passed in .

Input Data analysis

Or the above transaction Input Data “0xa0712d6800000000000000000000000000000000000000000000000000000000000000fa” For example .

Method identification

First of all, there are loopholes in the contract “def mint(uint256 _wad) payable:”, use keccak256 Work out ”mint(uint256)” Hexadecimal of the hash value of , Take the top eight at the same time to get Input Data Method name ID of “a0712d68” 了 .( Note that the computed hash only needs to be the function name + Parameter type )

Method parameter

After the method id is confirmed , You need to pass in mint Number , If you need one mint 250 individual , The introduction 250 The hexadecimal of “fa”.

Above mint The parameter in the method is uint256 Type of , You need to use the corresponding number of digits when spelling in parameters ,uint256 If the parameter of type is changed to 16 In hexadecimal, you need 64 position , So will “fa” repair 0 To 64 Bit is “00000000000000000000000000000000000000000000000000000000000000fa”.

Pieced together Input Data

At this time, it is identified with the previously calculated method name “a0712d68” Piece together , You can get “a0712d6800000000000000000000000000000000000000000000000000000000000000fa” Of Input Data Data. , With the above Mint Of this transaction Of Input Data identical .( If you have more than one parameter , It is OK to continue to spell according to the length of the parameter type )

Put this Input Data The data is in Metamask Enter... When transferring to the contract address , The Ethereum miner node knows which method to execute the contract and what parameters to pass in .

Last

If you still don't understand , It's just Etherscan Compare the contract and transaction Of InputData, In fact, they can work it out by themselves .

The above contents do not make any investment suggestions , Investment is risky !

原网站

版权声明
本文为[NFT practitioner]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261529207330.html