Transaction Types and Usage
Transactions are the fundamental operations that alter the state of the ArcBlock blockchain. Every action, from creating an account to transferring an NFT, is executed as a transaction. This section provides a comprehensive guide to the various transaction types available, their structure, and how to utilize them effectively with the @arcblock/graphql-client
.
Before proceeding, it's recommended to have a basic understanding of Core Blockchain Concepts, particularly Wallets and Accounts, as they are integral to creating and signing transactions.
The Anatomy of a Transaction#
To ensure flexibility and extensibility, ArcBlock transactions adopt a mail-like structure, separating the container from the content.
- Envelope: The outer transaction, which contains fields required for all transactions, such as the sender's address, public key, and signature.
- Letter: The inner transaction (
itx
), which holds the actual content and logic for a specific operation, like aDeclareTx
orTransferV2Tx
.
This layered design allows for a consistent handling process while supporting a wide variety of operations.
The outer transaction structure is consistent across all types:
type Transaction = {
from: string; // Sender's address
pk: string; // Sender's public key
nonce: number;
chainId: string; // Must match the target chain
signature: string; // Sender's signature
signatures: Array<Multisig>; // For multi-party scenarios
itx: Any; // The inner transaction
};
The inner transaction (itx
) varies depending on its type
. The Any
type is used to encapsulate different data structures within a single field, providing a high degree of flexibility.
Transaction Lifecycle#
From creation to confirmation, a transaction follows a clear, verifiable path. The @arcblock/graphql-client
simplifies this process, but understanding the steps is key to building robust applications.
Common Transaction Characteristics#
While each transaction type serves a unique purpose, they share several common characteristics regarding fees, size, and signatures.
Transaction Fees#
Fees are a mechanism to prevent network abuse and fund certain operations. Three types of fees may be charged:
Fee Type | Description |
---|---|
Service Fee | Charged for moving tokens across an ArcBridge using |
Protocol Fee | Charged for protocol-level operations like |
Gas Fee | A standard fee for computational resources. It is not currently enabled on the main or beta chains. |
Transaction Size Limit#
To protect the chain from abuse, each transaction type has a hard size limit, measured in bytes after encoding. Transactions exceeding their limit will be rejected during verification. The specific limits for each transaction type are detailed in their respective documentation sections.
Transaction Signatures#
Signatures are cryptographic proof that a transaction is authentic and has not been tampered with.
- Sender Signature: Every transaction must be signed by the sender. The network verifies this signature using the sender's public key, which is stored on-chain with their account.
- Multi-party Signature: Some operations require consent from multiple parties. ArcBlock has native support for multi-party signatures in transactions like
TransferV3Tx
andAcquireAssetV3Tx
(when there are multiple payers) and in most ArcBridge-related transactions, which require signatures from all validators.
Exploring Transaction Types#
Transactions are grouped by their function. The following sections provide detailed guides and code examples for each category. Choose a category to learn more about its specific transactions and how to use the client's helper methods to implement them.
- Account Transactions: For managing identities, such as declaring an account or delegating permissions.
- NFT Transactions: For creating, updating, minting, and transferring Non-Fungible Tokens.
- Token Transactions: For creating and managing fungible tokens, including cross-chain deposits and withdrawals.
- Trading Transactions: For exchanging assets and tokens between parties.
- Staking Transactions: For participating in the network's consensus and security by staking tokens.
- ArcBridge Transactions: For managing and interacting with ArcBridge sub-chains.
Now that you have an overview of how transactions work, a great place to start is with Account Transactions, as declaring an account is often the first step in any blockchain application.