Custom Instruction

How to create a custom instruction to be executed via Realms

Create a Custom Instruction

SPL Governance proposals can execute arbitrary on-chain instructions once a vote succeeds. This is the core mechanism that makes DAOs powerful: any instruction that can be called by a Solana program can be governed by a vote.

How Proposal Transactions Work

A Proposal can contain multiple ProposalTransactions, each with multiple instructions. After a successful vote, anyone can trigger execution once the hold_up_time has elapsed. The instructions are signed by the Governance PDA (specifically the DAO Wallet), giving them authority over any assets the DAO controls.

Two Transaction Types

SPL Governance v3.1.2 supports two types of proposal transactions:

  1. Legacy Transactions (InsertTransaction) - The original format using InstructionData

  2. Versioned Transactions (InsertVersionedTransaction) - New in v3.1.2, supports Address Lookup Tables and larger transactions

Creating a Legacy Proposal Transaction

InstructionData Format

Each instruction in a proposal transaction is encoded as:

pub struct InstructionData {
    /// Target program ID
    pub program_id: Pubkey,
    /// Account metadata for the instruction
    pub accounts: Vec<AccountMetaData>,
    /// Instruction data bytes
    pub data: Vec<u8>,
}

pub struct AccountMetaData {
    pub pubkey: Pubkey,
    pub is_signer: bool,
    pub is_writable: bool,
}

Step-by-Step: Adding an Instruction to a Proposal

1. Create the proposal:

2. Insert a transaction with your custom instruction:

3. Sign off the proposal to begin voting:

Creating Versioned Transactions (v3.1.2)

For larger instructions or when you need Address Lookup Tables, use versioned transactions:

Direct Insert (Small Transactions)

Buffered Insert (Large Transactions)

For transactions that exceed the Solana transaction size limit, use the buffer mechanism:

Common Custom Instruction Patterns

Program Upgrade

The most common governance action - upgrading a program:

Token Transfer from Treasury

Mint Tokens

Call Any Program

You can create instructions for any program. The key insight is that the Governance PDA (DAO Wallet) acts as a signer, so it can authorize any action where it holds authority:

Important Notes

  • DAO Wallet vs Governance PDA: Always use the DAO Wallet (native treasury) as the authority over assets. It is a PDA with no data, derived from the Governance account, and owned by the System program. It behaves like a regular wallet.

  • hold_up_time: Set this to add a delay between vote completion and execution. This gives the community time to react to controversial proposals.

  • Multiple transactions per option: A proposal option can have multiple transactions that execute independently.

  • Execution is permissionless: Once the vote passes and hold-up time elapses, anyone can trigger execution.

Last updated