1. The meaning of the fields of a single transaction in Ethereum

Consumers can interact with Ethereum through Metamask and mist browsers, and developers can interact with Ethereum through the web3js tool library.

 

Fields required for a single transaction: 

nonce :

  definition

  1. The official document explains the nonce:
nonce: QUANTITY - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.

     2. Personal definition: Every time a transaction is initiated, the nonce will increase by one (the nonce count starts from 0, if your account has 5 transfer transactions, then the last nonce value will be 4).

        Explanation for initiation:
        1. Every time an external account (EOA) sends a transaction;
        2. Every time a contract is created by a contract account (Contract Wallet)

        However, transfer-in transactions, contract calls to other contracts, etc. are internal calls, so the nonce value remains unchanged.

  effect

  1. Determine the order of transactions. If you send two transactions back and forth and want them to be packaged sequentially, then miners can package them in the order of nonce.
  2. To prevent replay attacks, if there is no nonce, the transaction information is generated in a sequence that others can see and submit repeatedly, thus emptying your wallet. With nonce, transactions with the same nonce can only be packaged once after the sequence is generated.
  3. Accelerated transactions, based on the characteristics of nonce, self-increment and uniqueness, can be accelerated by re-initiating transactions with the same nonce. Example: If a transaction A has gas price = 5, nonce = 1, and the transaction is in the pending state after broadcasting, create transaction B and set the gas price higher, such as 10, 20, nonce=1, and publish the transaction again. At the transaction pool side, transaction B is packaged first, and miners will check transaction A and find that the nonce already exists. If they think that transaction A is unreasonable, they will automatically discard the transaction. (If the transaction is packaged, that is, in a non-pending state, it is irreversible and cannot be canceled or accelerated.)
  4. cancel the deal. Based on the case of accelerated transactions. Create transaction B, set value = 0 nonce = 1 (that is, the nonce value of A transaction), payee = sender, set a higher gas price, broadcast the transaction, the original transaction is discarded, and the new transaction will be mined Pack it up without losing any funds. But you still need to pay miner fees for transaction B.

  rules of use

  1. When the nonce is too small (less than the current nonce value), the transaction will be directly rejected, Transactions with too low a nonce get immediately rejected;
  2. When the nonce is too large, greater than the current nonce, the transaction will always be in the queue, Transactions with too high a nonce get placed in the transaction pool queue;
  3. When sending a relatively large nonce value, and then filling the nonce between the start nonce and that value, the transaction can still be executed. If transactions with nonces that fill the gap between the last valid nonce and the too high nonce are sent and The nonce sequence is complete, all the transactions in the sequence will get processed and mined.
  4. The transaction queue only saves up to 64 transactions sent from the same account, that is to say, if you want to transfer money in batches, the same node should not send more than 64 transactions. The transaction pool queue will only hold a maximum of 64 transactions with the same From:address with nonces out of sequence.
  5. When there are transactions in the queue of a certain node, but the geth client is stopped at this time, the transactions in the queue will be cleared. When the geth instances are shut down and restarted, transactions in the transaction pool queue disappear.
  6. If the current nonce is suitable, but the account balance is insufficient, it will be rejected by Ethereum;

to :

        The account address to which the money will be transferred.

value :

        The amount of tokens to send to the target address.

        In the transaction of creating a contract, this value is used as the initial balance in the newly created contract account.

gas price :

        One ETH is divided into: Finney, Szabo, Gwei, Mwei, Kwei and Wei, where Wei is the smallest ETH unit, and one ETH is equal to one thousand Finney, one million Szabo, one billion Gwei and one million trillion Wei.

        Gas Price is the amount in Gwei, the amount that users are willing to spend for each Gas unit.

gas limit :

        Gas Limit is the maximum amount of Gas a user is willing to pay for performing an operation or confirming a transaction (minimum 21,000). 

        When conducting each transaction, the sender sets the Gas Limit and Gas Price, and the Gas Limit*Gas Price is calculated to obtain the cost of the ETH transaction commission.

Combining gas price and gas limit:

        If 1Gwei≈0.00000002 ETH, the minimum commission is 0.00000002*21000=0.00042 ETH. Normally, the gas limit of the transaction setting is 50000-100000, and the total fee is 0.001 ETH-0.002 ETH.

Questions to consider when setting the Gas limit:

  • Different operations will have different Gas costs.
  • When the gas is used up, the miner will stop executing.
  • If there is remaining Gas, it will be refunded immediately to the person who initiated the transaction or the creator of the smart contract.
  • If the limit value set by the user is too low, the transaction is considered invalid and will be canceled with an "insufficient gas" error, and the gas used for the calculation will not be refunded to the account.
  • Regardless of whether the transaction is passed or not, the sender always needs to pay the miner a computing fee.

V、R、S :

        An encrypted block of data generated from the sender's private key that can be used to generate the sender's account address. is the value of the transaction signature, they can be used to obtain the sender account address (public key). In detail, R and S are the output of an ECDSA signature, and V is the recovery ID. This mechanism is very useful in preventing replay attacks.

init (only exists in the transaction that creates the contract):

       EVM code snippet for initializing a new contract account. init is run only once and then discarded. When init is run for the first time , it returns the body of the accountcode, which is a piece of code permanently associated with the contract account.

data (optional field, only exists in the message call):

Input data (i.e. parameters) for the message call. For example, if a smart contract is used as a domain registration service, a call to that contract may require input fields such as domain and IP address.

Guess you like

Origin blog.csdn.net/qq_35784487/article/details/121313505