Transactions
What Is a Transaction?
A transaction is a cryptographically signed instruction initiated by an externally owned account. Once executed, the state of the XDC network is updated. The simplest transaction involves transferring XDC from one account to another. For example, if Ben sends Ana 1 XDC, his account will be debited, and Ana's will be credited 1 XDC. Both of these state-changing actions occur in the space of a single transaction.
Transactions are broadcast by nodes to the entire network to be executed on the virtual machine. A validator will execute the transaction and circulate the resulting state change to the entire network.
A submitted transaction consists of the following details:
signature
: The sender's identifier, generated by signing the transaction with the sender's private key that confirms its authorization.recipient
: The receiving address. The transaction will transfer value for an externally owned account. However, for a contract account, it will execute the contract code.value
: The amount of XDC to transfer from sender to recipient.data
: An optional field that allows the inclusion of arbitrary data.gasPrice
: The fee charged per unit of gas.gasLimit
: The maximum amount of gas units that the transaction can consume. Units of gas represent computational steps.
Gas is the reference to the computational power required for a validator to execute the transaction. Users will have to pay a fee for this computation. The gasPrice
and gasLimit
determine the maximum transaction fee paid to the validator.
The transaction object looks like this:
A transaction object is signed using the sender’s private key, ensuring that the transaction arrived from the authorized sender and was not sent fraudulently.
Example of a Transaction
It is necessary to have the private key associated with the sender’s address to transfer XDC from one account to another:
We need to create an instance of XDCTransaction with values we want to send to the account.
Now, we need to call the eth_sendRawTransaction method.
We will receive one txHash, which will include all data of the transaction.
Response:
The transaction’s signature hash is cryptographically proven, verifying that it came from the legitimate sender.
Gas
As already mentioned, transactions cost gas to process. Simple transfer transactions may require 35000 units of gas.
So, for Ben to send Ana 1 XDC at a gasPrice
of 30 gwei, Ben will need to pay the following fee:
30 * 35000 = 1,050,000 gwei
--or--
0.00105 XDC
Ben's account is debited -1.00105 XDC
Ana's account is credited +1.0 XDC
The validator processing the transaction gets +0.00105 XDC
Gas is also required for smart contract interactions.
Gas is refunded to the user's account if it is not used in any transaction.
Transaction Life Cycle
Once the transaction is submitted, the following occurs:
After sending a transaction, cryptography generates a transaction hash, such as
0x903d735683c2959b86aea197a06583a30837b4a505465a0da2347f61d6daa533
The transaction is then streamed to the network and included in the pool of transactions.
A validator must pick the transaction and include it in a block to verify it and consider it successful. If the network is busy and validators cannot keep up, there may be a delay. Since validators get the fees, they will always prioritize transactions with higher
gasPrice
.The transaction will get a block confirmation number. It is the number of blocks created since the transaction's block was first included. A higher number provides a certainty that the network has successfully executed and recognized the transaction. A higher block confirmation number thus ensures the immutability of the transaction.
Last updated