Squads Docs
Development
Development
  • Introduction
    • What is Squads Protocol
    • Use Cases
    • Quickstart
  • Typescript
    • Overview
    • Instructions
      • Create Multisig
      • Create Config Transaction
      • Create Vault Transaction
      • Create Proposal
      • Approve Proposal
      • Reject Proposal
      • Cancel Proposal
      • Execute Config Transaction
      • Execute Vault Transaction
      • Create Batch
      • Add To Batch
      • Close Vault Transaction Account
      • Controlled Multisig Instructions
        • Add Member
        • Remove Member
        • Set Rent Collector
        • Add spending limit
        • Remove Spending Limit
    • Accounts
      • Multisig
      • Vault
      • Transactions
      • Proposal
      • Batch
  • Reference
    • Accounts
    • Permissions
    • Spending Limits
    • Time-locks
    • SDKs
    • Controlled Multisigs
  • API
    • Vault Check
  • CLI
    • Installation
    • Commands
  • Get Support
    • We're here to help
  • Other
    • Migrating from MultisigCreate v1 to v2
    • Squads Actions and Blinks
Powered by GitBook
On this page
  • Example
  • Notes
  1. Typescript
  2. Instructions

Add To Batch

Adding a transaction to an active batch account

When adding to a batch, a few things need to be kept in mind:

  • When a new transaction is added, a vault transaction will be initialized with this method, and the batch's local index will be incremented

  • The batchIndex field refers to the global index of the batch account (like any other transaction), while transactionIndex refers to the batch's inner index for the transaction being initialized (will start at 1 for the first transaction)

Example

import * as multisig from "@sqds/multisig";
import { Connection, PublicKey } from "@solana/web3.js"

async function main(member: PublicKey) {
    // Cluster Connection
    const connection = new Connection("<your rpc url>");
    
    // If you've saved your createKey, you can define it as a static PublicKey
    const createKey = new PublicKey("<your createkey>")
    
    // Derive the multisig PDA
    const [multisigPda] = multisig.getMultisigPda({
        createKey,
    });
    // or
    // const multisigPda = new PublicKey("<your multisig key>");
    
    // Get deserialized multisig account info
    const multisigInfo = await multisig.accounts.Multisig.fromAccountAddress(
      connection,
      multisigPda
    );

    // Get the current transaction index
    const transactionIndex = Number(multisigInfo.transactionIndex);
    // or, if this is tied to your first transaction
    // const transactionIndex = 1n;
    
    const instruction = SystemProgram.transfer({
        fromPubkey: vaultPda,
        toPubkey: creator.publicKey,
        lamports: 1,
    });
      // This message contains the instructions that the transaction is going to execute
    const transferMessage = new TransactionMessage({
        payerKey: vaultPda,
        recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
        instructions: [instruction],
    });
    
    // Add transaction to the batch
    const batchAddIx = await multisig.instructions.batchAddTransaction({
        // Index of the batch globally, like any other transaction
        batchIndex: BigInt(newTransactionIndex),
        multisigPda,
        vaultIndex: 0,
        transactionMessage: transferMessage,
        // Index of the transaction inside of the batch! Not globally. Starts at 1
        transactionIndex: 1,
        ephemeralSigners: 0,
        member: creator,
    });
}

Notes

  • A Vault Transaction is initialized when you add to a batch

  • batchIndex field refers to a global index, while transactionIndex refers to the batch's inner index

PreviousCreate BatchNextClose Vault Transaction Account

Last updated 8 months ago