Transactions
Transactions are collections of instructions for the blockchain to execute.
Overview
A transaction in BBAChain is a set of instructions that are executed atomically. If any instruction in a transaction fails, the entire transaction is rolled back.
Transaction Structure
A transaction consists of:
- Signatures: Cryptographic signatures from the transaction's fee payer and other required signers
- Message: Contains the instructions, account keys, recent blockhash, and other metadata
- Instructions: The actual operations to be performed
Transaction Lifecycle
- Creation: A transaction is created with one or more instructions
- Signing: The transaction is signed by required signers
- Submission: The transaction is submitted to the network
- Processing: Validators process the transaction
- Confirmation: The transaction is confirmed and finalized
Example
import {
Connection,
Keypair,
Transaction,
SystemProgram,
} from "@bbachain/web3.js";
const connection = new Connection("https://api-mainnet.bbachain.com");
const fromKeypair = Keypair.generate();
const toPubkey = Keypair.generate().publicKey;
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: fromKeypair.publicKey,
toPubkey: toPubkey,
daltons: 1000000,
})
);
const signature = await connection.sendTransaction(transaction, [fromKeypair]);
Transaction Fees
Every transaction in BBAChain requires a fee paid in BBA. The fee is deducted from the transaction's fee payer account.
Commitment Levels
BBAChain provides different commitment levels for transaction confirmation:
- Processed: Transaction has been included in a block
- Confirmed: Transaction has been confirmed by the cluster
- Finalized: Transaction has been finalized and cannot be rolled back
Next Steps
- Learn about Accounts
- Understand Programs
- Explore Cross-Program Invocation