Skip to main content
The SwigInstructionBuilder is a fundamental component of the Swig SDK that handles the creation and management of Solana instructions for the Swig protocol.

Overview

The instruction builder provides low-level functionality for creating various types of instructions needed to interact with Swig wallets on the Solana blockchain.

Core Components

AuthorityManager

The AuthorityManager enum represents different types of signing authorities supported by the Swig protocol.

SwigInstructionBuilder

Core Functions

Creating a New Instance

Creates a new instance of the instruction builder with the specified parameters.

Building a Swig Account

Creates an instruction to initialize a new Swig account on-chain.

Signing Instructions

Creates signed instructions for the provided transaction instructions.

Authority Management

Adding Authorities

Creates an instruction to add a new authority with specified permissions.

Removing Authorities

Creates an instruction to remove an existing authority.

Replacing Authorities

Creates instructions to replace an existing authority with a new one.

Session Management

Creating Sessions

Creates an instruction to create a new session for temporary authority delegation.

Utility Functions

Getting the Swig Account

Returns the public key of the Swig account.

Getting the Role ID

Returns the current role ID of the Swig account.

Switching Authority

Switches the current authority and role ID.

SubAccount Management

Creating SubAccounts

New in v1.4.0: Support for multiple subaccounts per role (indices 0-254).
Creates an instruction to create a subaccount at a specific index (0-254). Parameters:
  • sub_account_index: The index of the subaccount to create (0-254). Index 0 uses legacy PDA derivation for backwards compatibility.

Deriving SubAccount PDAs

The derive_sub_account_pda function automatically handles:
  • Index 0: Uses legacy 3-seed PDA derivation for backwards compatibility
  • Indices 1-254: Uses new 4-seed PDA derivation with index in seeds

Examples

Creating a New Swig Account

Adding a New Authority

Adding Authority with Multiple SubAccount Permissions

Creating Multiple SubAccounts