Skip to main content

Overview

The build transaction endpoint constructs a Solana transaction from an Anchor IDL instruction definition. It handles argument encoding, account validation, and transaction serialization.

Endpoint

POST /api/:projectId/instructions/:name/build

Request Body

accounts
object
required
Map of account names to public keys (base58 format)
{
  "user": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
  "systemProgram": "11111111111111111111111111111111"
}
args
object
required
Map of argument names to values. Types are automatically encoded based on the IDL.Supported types:
  • Primitives: u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, f32, f64, bool
  • Complex: string, publicKey, bytes
  • Collections: Vec<T>, [T; N] (fixed-size arrays)
  • Optional: Option<T>
  • Custom: Defined structs from IDL types
{
  "amount": 1000000,
  "recipient": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
  "config": {
    "feeRate": 100,
    "enabled": true
  }
}
feePayer
string
required
Public key (base58) of the transaction fee payer
recentBlockhash
string
Optional recent blockhash. If not provided, it will be fetched from the RPC.
network
string
default:"mainnet"
Network to use for RPC calls:
  • "mainnet" or "mainnet-beta" - Solana mainnet
  • "devnet" - Solana devnet
  • Custom RPC URL (e.g., "https://api.custom-rpc.com")

Response

transaction
string
Base58-encoded serialized transaction message
message
string
Human-readable description of the transaction
accounts
array
List of accounts used in the instruction
instruction
object
Detailed instruction information
estimatedFee
number
Estimated transaction fee in lamports (typically 5000)

Example

curl -X POST https://api.orquestra.so/api/my-project/instructions/transfer/build \
  -H "Content-Type: application/json" \
  -d '{
    "accounts": {
      "from": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
      "to": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
      "systemProgram": "11111111111111111111111111111111"
    },
    "args": {
      "amount": 1000000
    },
    "feePayer": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
    "network": "devnet"
  }'

Response Example

{
  "transaction": "3yZe7d4FVmqPGPKqRLdnKpC...",
  "message": "Transaction for my_program.transfer",
  "accounts": [
    {
      "name": "from",
      "pubkey": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
      "isSigner": true,
      "isWritable": true
    },
    {
      "name": "to",
      "pubkey": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
      "isSigner": false,
      "isWritable": true
    },
    {
      "name": "systemProgram",
      "pubkey": "11111111111111111111111111111111",
      "isSigner": false,
      "isWritable": false
    }
  ],
  "instruction": {
    "name": "transfer",
    "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    "data": "a7b3c4d5e6f7890102030405060708091011121314151617181920",
    "accounts": [
      /* same as accounts array above */
    ]
  },
  "estimatedFee": 5000
}

Error Responses

400 Bad Request
  • Missing required fields (accounts, args, or feePayer)
  • Invalid build request (missing required accounts/arguments)
  • Invalid public key format
404 Not Found
  • Project not found or not public
  • Instruction not found in IDL
500 Internal Server Error
  • Failed to build transaction
  • RPC connection error

Validation

The endpoint performs the following validations:
  1. Account Validation
    • All required accounts must be provided
    • Public keys must be valid base58 (32-44 characters)
    • Unknown account names are rejected
  2. Argument Validation
    • All required arguments must be provided
    • For defined types (structs), all fields must be present
    • Type validation based on IDL definitions
  3. Transaction Building
    • Instruction discriminator: SHA-256 hash of "global:<instruction_name>" (first 8 bytes)
    • Arguments encoded using Borsh serialization
    • Recent blockhash fetched if not provided

Rate Limiting

This endpoint is rate-limited to prevent abuse. See Rate Limiting for details.

Build docs developers (and LLMs) love