Transactions
Solana Transactions¶
In Solana, a Transaction is the fundamental unit through which users interact with the blockchain. A transaction contains one or more Instructions, each of which invokes a program to perform a specific operation. Solana's transaction design emphasizes high performance and atomicity.
Transaction Structure¶
A complete Solana transaction contains:
1. Signatures - One or more signatures - Corresponding to the signers in the transaction - Using the Ed25519 elliptic curve algorithm
2. Message Contains the core content of the transaction: - Header: Specifies the number of accounts requiring signatures, the number of read-only accounts, etc. - Account Keys: All account addresses involved in the transaction - Recent Blockhash: Prevents replay attacks - Instructions: The operations to be executed
Transaction Lifecycle¶
1. Build the Transaction
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: sender.publicKey,
toPubkey: receiver.publicKey,
lamports: 1000000,
})
);
2. Set the Recent Blockhash
3. Sign
4. Send
5. Confirm
Transaction Limits¶
Size Limit - Maximum 1,232 bytes (after serialization) - Limits the number of accounts and instructions - Exceeding the limit requires splitting into multiple transactions
Compute Limit - Default: 200,000 CU - Maximum requestable: 1,400,000 CU - Adjustable via ComputeBudgetInstruction
Account Limit - A single transaction can lock at most 64 writable accounts - No limit on read-only accounts - Accounts cannot be duplicated (each account can only appear once)
Transaction Fees¶
Base Fee - 5,000 lamports per signature - Multi-signature transactions cost more
Priority Fee - Based on CU consumption and CU price - Increasing the priority fee during network congestion can speed up confirmation
Atomicity¶
Solana transactions are atomic: - All instructions either succeed entirely or fail entirely - No partial execution occurs - On failure, the state is completely rolled back
This allows complex multi-step operations (such as DEX trades) to execute safely.
Transaction Status¶
Processed - The transaction has been executed and included in a block - May be rolled back - Confirmation time: <1 second
Confirmed - The block has received votes from more than ⅔ of validators - Extremely low probability of rollback - Confirmation time: approximately 400-600 milliseconds
Finalized - The block is fully determined and irreversible - Confirmation time: approximately 13-15 seconds
Common Transaction Types¶
1. Token Transfer
const instruction = Token.createTransferInstruction(
TOKEN_PROGRAM_ID,
source,
destination,
owner,
[],
amount
);
2. Create Account
SystemProgram.createAccount({
fromPubkey: payer,
newAccountPubkey: newAccount,
lamports: rentExemption,
space: dataSize,
programId: ownerProgram,
});
3. Cross-Program Invocation Invoking instructions from other programs within a program.
Transaction Optimization¶
1. Batch Operations Combine multiple operations into a single transaction to save fees and time.
2. Priority Fee Setting
3. Lookup Tables Use Address Lookup Tables to reduce transaction size and overcome the 64-account limit.
Related Concepts¶
- Instruction: A component of a transaction that invokes a program to perform an operation
- CU (Compute Units): Measures the computational resources consumed by a transaction
- Blockhash: A timestamp used to prevent transaction replay
- Atomicity: A transaction either succeeds entirely or fails entirely