Transaction
Overview of how transactions function within the Xone Blockchain. Transactions are the fundamental building blocks of Xone, facilitating user interactions, state changes, and cross-chain communication.
1. What is a Transaction?
A transaction on the Xone Chain represents a signed message that initiates a specific action on the network. Transactions can trigger state transitions, execute smart contracts, transfer assets, or interact with modules like staking and governance.
Key components of a transaction include:
Fields | Explain |
---|---|
Sender Address | The account initiating the transaction. |
Recipient Address(optional) | The target account or contract. |
Value | The amount of tokens being transferred (if applicable). |
Data | Additional information for executing a contract or custom logic. |
Signature | A cryptographic signature from the sender, ensuring authenticity and integrity. |
Gas | Computational resources required to process the transaction. |
2. Transaction Lifecycle
2.1 Creation
A transaction is created by a user or DApp using a Web3-compatible wallet or API. The transaction includes the necessary fields such as the sender, recipient, value, and gas limit.
{
"from": "0xSenderAddress",
"to": "0xRecipientAddress",
"value": "1000000000000000000", // 1 Xone in wei
"gas": 21000,
"gasPrice": "20000000000"
}
2.2 Signing
The sender signs the transaction using their private key. This signature is used to verify that the transaction was authorized by the account owner.
Transaction Hash: 0xTransactionHash
Signature: 0xSignature
2.3 Broadcasting
The signed transaction is broadcasted to the network through an RPC endpoint or directly from a wallet.
curl -X POST https://Xone.rpc.endpoint \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xSignedTransaction"],"id":1}'
2.4 Propagation
The transaction is shared across the peer-to-peer network using the Gossip Protocol. Nodes validate the transaction and add it to their local mempool.
2.5 Inclusion in a Block
Validators include the transaction in a block during the next block proposal phase. The transaction consumes gas based on its computational complexity.
2.6 Execution
The transaction is executed by the state machine. If successful, the state of the blockchain is updated.
Example: Executing a Smart Contract
Sender: 0xUserAddress
Contract: 0xContractAddress
Function Call: transfer(address recipient, uint256 amount)
3. Transaction Types
3.1 Basic Transactions
Purpose: Transfer Xone tokens from one account to another.
- Sender
- Recipient
- Value
- Gas
{
"from": "0xUserAddress",
"to": "0xRecipientAddress",
"value": "1000000000000000000",
"gas": 21000
}
3.2 Smart Contract Transactions
Purpose: Deploy or interact with smart contracts.
- Sender
- Data (bytecode or function call)
- Gas
{
"from": "0xUserAddress",
"to": "0xContractAddress",
"data": "0xa9059cbb0000000000000000000000000xRecipientAddress0000000000000000000000000000000000000000000001",
"gas": 60000
}
3.3 Staking Transactions
Purpose: Delegate Xone tokens to a validator or withdraw rewards.
Xone tx staking delegate <validator-address> 1000xoc --from <user-address>
4. Gas and Fees
4.1 Gas Calculation
Gas measures the computational cost of executing a transaction. Each operation in the transaction consumes a predefined amount of gas.
Example: Gas Usage for a Transfer
Base cost: 21,000
gas
Additional data: 68
gas per byte.
4.2 Gas Price
Gas price is the fee paid per unit of gas. Users can specify higher gas prices to prioritize their transactions.
4.3 Fee Calculation
The total transaction fee is calculated as:
Fee = Gas Used × Gas Price
Example:
Gas Used: 21,000
Gas Price: 20 Gwei
Fee: 21,000 × 20 Gwei = 0.00042 XOC
5. Transaction Validity
5.1 Validation Rules
- The sender's account must have sufficient balance to cover the value and fees.
- The transaction nonce must match the sender's current nonce.
- The gas limit must be sufficient for execution.
5.2 Rejection Reasons
Insufficient Funds: Sender's balance is too low.
Invalid Nonce: The nonce is not sequential.
Gas Limit Exceeded: The gas provided is insufficient to complete the transaction.
6. Advanced Concepts
6.1 Transaction Nonces
Nonces ensure transactions from the same sender are executed in order. Each new transaction must increment the nonce by 1.
6.2 Replay Protection
Each transaction is uniquely identified by the sender's address, nonce, and signature, preventing replay attacks.
6.3 Atomic Transactions
Multiple transactions can be executed atomically within smart contracts, ensuring all or none of the operations are applied.