Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What happens in the ethernet square transaction

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what will happen in the Ethernet Square transaction". In the operation of the actual case, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Etay Fong can be thought of as a state machine based on transactions, where transactions can change state, and status tracking interactions. Here, we examine the components of the transaction at a high level and explain how most of the garbled hexadecimal values are determined.

We will use nodejs in this tutorial, so we will install the dependencies first.

$npm install web3@0.19 ethereumjs-util@4.4 ethereumjs-tx@1.3

Then create a file tx.js and require dependencies.

Var Web3 = require ('web3'); var web3 = new Web3 (new Web3.providers.HttpProvider (' https://ropsten.infura.io/'));var util = require ('ethereumjs-util'); var tx = require (' ethereumjs-tx'))

First, let's start with a private key. Tai Fong uses public key encryption for authentication. More specifically, an elliptic curve digital signature algorithm (ECDSA) with secp256k1 curves is used. Except for some restrictions, the private key is just a random 256-bit data. For example:

Var privateKey = '0xc0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec

Export the corresponding public key:

Var publicKey = util.bufferToHex (util.privateToPublic (privateKey))

If you print out publicKey, you should get the following:

0x4643bb6b393ac20a6175c713175734a72517c63d6f73a3ca90a15356f2e967da03d16431441c61ac69aeabb7937d333829d9da50431ff6af38536aa262497b27

The Ethernet Square address associated with the private key is the last 160 bits of the SHA3-256 (Keccak) hash of the public key.

Var address = '0x' + util.bufferToHex (util.sha3 (publicKey)) .slice (26); / / 0x53ae893e4b22d707943299a8d0c844df0e3d5557

As you can see, multiple private keys may actually have the same address. Ethernet Fong accounts are associated with each address, and each account has the following attributes:

The count of outgoing transactions from nonce starting at 0.

The number of etheric coins in balance.

StorageRoot the hash associated with the account store.

CodeHash manages the hash of the account's code, and if this is empty, then the account is a normal account that can be accessed using its private key, otherwise it is a smart contract and its interaction is managed by its code.

Next, let's look at a transaction with six input fields:

The count of outgoing transactions from nonce starting at 0.

The gasPrice price determines the amount of Ethernet that the transaction will cost.

The maximum gas allowed by gasLimit to process transactions.

The account to which the to transaction is sent, and if it is empty, the transaction will create a contract.

Estimate the value of the Ethernet to be sent.

Data can be any message or function call to a contract or code to create a contract.

A transaction that sends an ether of 1000wei (1ether = 10 to the power of 18 wei) and leaves a 0xc0de message can be constructed as follows:

Var rawTx = {nonce: web3.toHex (0), gasPrice: web3.toHex (20000000000), gasLimit: web3.toHex (100000), to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85), value: web3.toHex (1000), data:' 0xc0de'}

Note that the sender from address is not specified and will be derived from the signature when signed with the private key. Sign the transaction:

Var p = new Buffer ('c0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0

The transaction can then be sent to the network and tracked by the 256bit transaction id. This deal can be viewed at Etherscan. Trading id is the hash of the transaction.

Console.log (util.bufferToHex (transaction.hash (true); / / 0x8b69a0ca303305a92d8d028704d65e4942b7ccc9a99917c8c9e940c9d57a9662

Next, let's take a look at the data data composition of the function call. Take the data for this transaction as an example:

Console.log (web3.eth.getTransaction ('0xaf4a217f6cc6f8c79530203372f3fbec160da83d1abe048625a390ba1705dd57') .input); / / 0xa9059cbb0000000000000000000000007adee867ea91533879d083dd47ea81f0eee3a37e000000000000000000000000000000000000000000000000d02ab486cedbffff

In order to know which function it is calling, you must know the contract function in advance to create a hash table. The first 32-bit a9059cbb is the first 32-bit of the function hash. In this case, the function is transfer (address _ to,uint256 _ value), and its hash value is:

Console.log (web3.sha3 ('transfer (address,uint256)')); / / 0xa9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b

Each parameter is followed by 256 bits, so in this case the address is:

0x0000000000000000000000007adee867ea91533879d083dd47ea81f0eee3a37e

And unsigned integers are:

0x000000000000000000000000000000000000000000000000d02ab486cedbffff

Next, as mentioned above, the contract is created by omitting the to field. But how is the address of the contract determined? Take this deal as an example:

Console.log (web3.eth.getTransactionReceipt ('0x77a4f46ff7bf8c084c34293fd654c60e107df42c5bcd2666f75c0b47a9352be5'); / / 0x950041c1599529a9f64cf2be59ffb86072f00111

The contract address is the last 160bit hash of the sender's address, and its nonce can be determined in advance. For this deal, you can find the sender and `nonce`` in the following ways:

Var contractTx = web3.eth.getTransaction ('0x77a4f46ff7bf8c084c34293fd654c60e107df42c5bcd2666f75c0b47a9352be5'); console.log (contractTx.from); / / 0x84f9d8b0e74a7060e20b025c1ea63c2b171bae6fconsole.log (contractTx.nonce); / / 0

Therefore, the contract address is:

Console.log ('0x' + util.bufferToHex (util.rlphash ([' 0x84f9d8b0e74a7060e20b025c1ea63c2b171bae6fshield, 0])) .slice (26); / / 0x950041c1599529a9f64cf2be59ffb86072f00111

This is the end of the content of "what will happen in the Ethernet Square transaction". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report