概览
Transaction is an important concept in blockchain. 如果你不熟悉交易的概念,并希望快速了解它,你可以阅读 交易快速入门。
Typically, we use wallets or SDKs to send transactions, and these tools will assist us in completing complex tasks such as constructing transactions, sending them to the network, and ultimately waiting for the transaction be confirmed or finalized, making the process relatively straightforward.
However, if you wish to delve deeper into the principles of transactions or encounter issues while sending transactions, you may need to understand the details of transactions.
Transactions Fields
A transaction consists of multiple fields, each with its own meaning and purpose. To understand their meanings and how to correctly set these fields, please refer to Transaction Fields. If a transaction fails to send or gets stuck without being mined, it may be due to incorrect settings of certain transaction fields.
Nonce
The nonce
field in a transaction is crucial, as it determines the execution order of transactions. Nonce updates are not real-time, so understanding the nonce is essential, especially when there is a need to quickly send transactions to the chain. Additional nonce management guidelines are also provided for such cases.
交易费用
The gas
, gasPrice
as well as storageLimit
fields in a transaction are also crucial. These fields are used to set the execution cost of the transaction. Setting gas
too low may result in transaction failure, while setting it too high leads to unnecessary fees. The gasPrice
field affects the transaction's priority in the block, particularly in congested networks. storageLimit
is a unique field used to specify storage collateral could be used by a transaction. Understanding the transaction fee can help you set the fields more effectively.
Encoding and Signing
After preparing all transaction fields, the transaction needs to be encoded and signed according to specific rules before being sent. It is then sent to the network using the RPC method cfx_sendRawTransaction
.
Lifecycle
Once a transaction is sent to the network, it doesn't immediately get mined and executed. Instead, it undergoes a series of state changes. Understanding the transaction lifecycle can help you better comprehend the status changes of a transaction and troubleshoot issues encountered during the transaction sending process.