backtrader
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers,…
Solana transaction construction including instruction building, account resolution, compute budget, priority fees, and versioned transactions
$ npx -y skills add agiprolabs/claude-trading-skills --skill solana-tx-building --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/solana-tx-buildingContext preview
The summary Claude sees to decide when to auto-load this skill.
Solana transaction construction including instruction building, account resolution, compute budget, priority fees, and versioned transactions
name: solana-tx-building description: Solana transaction construction including instruction building, account resolution, compute budget, priority fees, and versioned transactions
This skill covers how to construct, simulate, and inspect Solana transactions programmatically. It addresses the full anatomy of a Solana transaction — from raw instruction encoding to versioned transaction formats, compute budget management, priority fees, and address lookup tables.
**Safety**: This skill is for transaction *construction* and *analysis* only. Scripts in this skill NEVER sign or submit real transactions. Always simulate before sending. Never auto-sign.
A Solana transaction consists of:
1. **Signatures**: One or more Ed25519 signatures (64 bytes each) 2. **Message**: The serializable payload containing:
The hard limit is **1232 bytes** for the entire serialized transaction. This constrains how many instructions and accounts you can include. Strategies to stay within the limit:
Each instruction contains three fields:
Instruction {
program_id_index: u8, // Index into the account keys array
accounts: [u8], // Indices into account keys array
data: [u8], // Opaque byte array interpreted by the program
}Every account referenced in an instruction has metadata:
AccountMeta {
pubkey: Pubkey, // 32-byte public key
is_signer: bool, // Must sign the transaction
is_writable: bool, // Will be written to by this instruction
}The four combinations determine the account's role:
| is_signer | is_writable | Role | |-----------|-------------|------| | true | true | Fee payer, token owner performing transfer | | true | false | Multisig co-signer, read-only authority | | false | true | Destination account, PDA being written | | false | false | Program ID, sysvar, clock |
The original format. All accounts must be listed in the account keys array. With the 1232-byte limit, you can fit roughly 20-35 accounts depending on instruction data size.
Introduced to support **Address Lookup Tables (ALTs)**. A v0 transaction includes:
ALTs let you reference accounts by a compact index into an on-chain table rather than including the full 32-byte pubkey. This dramatically increases the number of accounts a transaction can reference.
AddressTableLookup {
account_key: Pubkey, // The ALT account address
writable_indexes: [u8], // Indices for writable accounts
readonly_indexes: [u8], // Indices for read-only accounts
}**When to use v0**: Any transaction referencing more than ~20 accounts, Jupiter swaps with multi-hop routes, complex DeFi interactions.
Every transaction has a compute budget that determines how many compute units (CUs) it can consume and what priority fee to pay.
Two key instructions from the Compute Budget Program (`ComputeBudget111111111111111111111111111111`):
**1. Set Compute Unit Limit**
Instruction data: [0x02, <units as u32 LE>]
Sets the maximum CUs this transaction can consume. Default is 200,000 per instruction (max 1,400,000 per transaction). Setting this lower than needed causes the transaction to fail. Setting it higher wastes budget but does not cost more (you only pay for requested, not consumed).
**2. Set Compute Unit Price**
Instruction data: [0x03, <micro_lamports as u64 LE>]
Sets the price per CU in micro-lamports. This is the priority fee mechanism. The total priority fee is:
priority_fee = compute_unit_limit * compute_unit_price / 1_000_000
To estimate an appropriate priority fee:
1. Call `getRecentPrioritizationFees` RPC method with the accounts your transaction touches 2. Look at the median or 75th percentile fee from recent slots 3. During congestion, fees spike — monitor and adjust dynamically
import httpx
def get_priority_fees(rpc_url: str, accounts: list[str]) -> list[dict]:
"""Fetch recent prioritization fees for given accounts."""
resp = httpx.post(rpc_url, json={
"jsonrpc": "2.0",
"id": 1,
"method": "getRecentPrioritizationFees",
"params": [accounts]
})
return resp.json()["result"]The simplest transaction: a System Program transfer.
# System Program transfer instruction data layout:
# [2, 0, 0, 0] (u32 LE = instruction index 2 = Transfer)
# + amount as u64 LE (lamports)
import struct
def build_sol_transfer_data(lamports: int) -> bytes:
"""Build instruction data for a SOL transfer."""
return struct.pack("<I", 2) + struct.pack("<Q", lamports)Accounts required: 1. Sender (signer, writable) 2. Recipient (writable)
Transferring SPL tokens requires the Token Program.
# Token Program transfer instruction:
# [3] (instruction index 3 = Transfer)
# + amount as u64 LE
def build_token_transfer_data(amount: int) -> bytes:
"""Build instruction data for an SPL token transfer."""A comprehensive collection of 68 ready-to-use trading, DeFi, and quantitative finance Agent Skills. Works with Claude Code, Cursor, Codex, Gemini CLI, and 30+ other tools.
Repo: agiprolabs/claude-trading-skills
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers,…
Solana token market data via Birdeye — prices, OHLCV, trades, token metadata, security…
Broad crypto market data from CoinGecko covering 13,000+ tokens. Global market stats,…
Cointegration testing for pairs trading using Engle-Granger, Johansen, and rolling stability…
Wallet evaluation, monitoring, and copy-trade strategy design for Solana DEX trading
Cross-asset correlation analysis including rolling correlation, hierarchical clustering, tail…