txbuilder

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package txbuilder provides a fluent transaction builder for Solana. It assembles Instructions into a signed Transaction without requiring any network access: blockhash and signers are provided by the caller.

Example:

tx, err := txbuilder.NewBuilder().
    SetFeePayer(payer.PublicKey()).
    Add(systemProgram.Transfer(...)).
    Add(memoProgram.Log("hello")).
    SetRecentBlockhash(bh).
    Sign(ctx, payer).
    Build()

Index

Constants

This section is empty.

Variables

View Source
var ComputeBudgetProgramID = solana.MustPublicKey("ComputeBudget111111111111111111111111111111")

ComputeBudgetProgramID is the on-chain address of the Compute Budget program, which controls per-transaction compute units and priority fees.

Functions

func SetComputeUnitLimit

func SetComputeUnitLimit(units uint32) solana.Instruction

SetComputeUnitLimit returns an Instruction that sets the per-transaction compute unit limit. Use this to cap compute consumption and avoid overpaying on compute fees.

units should be determined by simulation (SimulateTransaction) with a safety margin (e.g. actual * 1.1).

func SetComputeUnitPrice

func SetComputeUnitPrice(microLamports uint64) solana.Instruction

SetComputeUnitPrice returns an Instruction that sets the priority fee in micro-lamports per compute unit. Higher fees increase the probability of landing a transaction during congestion.

microLamports is the per-compute-unit fee in micro-lamports (1 lamport = 1,000,000 micro-lamports).

func ToMessageAddressTableLookup

func ToMessageAddressTableLookup(t AddressLookupTable) solana.MessageAddressTableLookup

ToMessageAddressTableLookup converts an AddressLookupTable to the solana.MessageAddressTableLookup wire type.

Types

type AddressLookupTable

type AddressLookupTable struct {
	AccountKey      solana.PublicKey
	WritableIndexes []uint8
	ReadonlyIndexes []uint8
}

AddressLookupTable associates an on-chain lookup table account with the indices of accounts within it that this transaction references. This is the wire-format representation used inside a compiled v0 Message; to build a v0 transaction from scratch use LoadedAddressLookupTable instead.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a fluent transaction assembler. All mutating methods return the receiver so calls can be chained. Build finalises the transaction; after Build returns the Builder must not be reused.

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns an empty Builder.

func (*Builder) Add

func (b *Builder) Add(ix solana.Instruction) *Builder

Add appends an instruction to the transaction. Instructions are executed in the order they are added.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) (*solana.Transaction, error)

Build compiles the instructions into a Message, constructs the Transaction, calls Sign on all registered signers, and returns the result. ctx is forwarded to each signer's Sign method.

Build returns an error if:

  • an instruction was nil (recorded by Add)
  • the blockhash is zero
  • the fee payer is zero
  • message compilation fails (e.g. too many accounts)
  • any signer returns an error

func (*Builder) BuildV0

func (b *Builder) BuildV0(ctx context.Context, tables []LoadedAddressLookupTable) (*solana.Transaction, error)

BuildV0 compiles the builder's instructions and the provided address lookup tables into a v0 versioned Message, constructs a Transaction, signs it with all registered signers, and returns the result.

tables must contain the fully resolved ALT data (key + all addresses stored in the table). The builder maps instruction accounts to table slots automatically: any non-signer account found in a table is routed through that table; all signer accounts and program IDs remain static.

Use BuildV0 instead of Build when the transaction references more accounts than the 35-account legacy limit, or when you need to save transaction bytes by referencing large shared account sets.

func (*Builder) SetFeePayer

func (b *Builder) SetFeePayer(payer solana.PublicKey) *Builder

SetFeePayer sets the transaction fee payer. The fee payer is the first signer and its public key is placed first in the account keys list.

func (*Builder) SetRecentBlockhash

func (b *Builder) SetRecentBlockhash(bh solana.Hash) *Builder

SetRecentBlockhash sets the recent blockhash the transaction commits to. This must be set before calling Build.

func (*Builder) Sign

func (b *Builder) Sign(signers ...solana.Signer) *Builder

Sign registers signers that will be asked to sign the serialized message when Build is called. Multiple Sign calls accumulate signers.

type LoadedAddressLookupTable

type LoadedAddressLookupTable = solana.LoadedAddressLookupTable

LoadedAddressLookupTable is a type alias for solana.LoadedAddressLookupTable. It holds the full resolved addresses for a lookup table and is the input type for Builder.BuildV0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL