> ## Documentation Index
> Fetch the complete documentation index at: https://new-docs.squads.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Add To Batch

## Overview

Add a transaction to an active batch account. When a new transaction is added, a vault transaction is initialized and the batch's local index is incremented.

## Prerequisites

* Existing batch with draft proposal
* `@sqds/multisig` package installed
* Member with Proposer permissions who created the batch

## Quick Example

```typescript theme={null}
import * as multisig from "@sqds/multisig";
import { Connection, PublicKey, SystemProgram, TransactionMessage } from "@solana/web3.js";

const batchAddIx = await multisig.instructions.batchAddTransaction({
  batchIndex: BigInt(newTransactionIndex),
  multisigPda,
  vaultIndex: 0,
  transactionMessage: transferMessage,
  transactionIndex: 1,
  ephemeralSigners: 0,
  member: creator,
});
```

## Important Distinction

* `batchIndex`: The **global** index of the batch account (like any other transaction)
* `transactionIndex`: The batch's **internal** index for the transaction being added (starts at 1)

## Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `multisigPda` | `PublicKey` | Yes | PDA of the multisig |
| `batchIndex` | `bigint` | Yes | Global index of the batch |
| `transactionIndex` | `number` | Yes | Internal index within the batch (starts at 1) |
| `vaultIndex` | `number` | Yes | Index of the vault for the transaction |
| `transactionMessage` | `TransactionMessage` | Yes | Message containing instructions to execute |
| `ephemeralSigners` | `number` | Yes | Number of ephemeral signers needed |
| `member` | `PublicKey` | Yes | Member adding the transaction |

## Full Example

```typescript theme={null}
import * as multisig from "@sqds/multisig";
import { Connection, PublicKey, SystemProgram, TransactionMessage } 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
    );

    // Index of the batch. Here the batch is the latest transaction of the multisig
    const batchIndex = BigInt(multisigInfo.transactionIndex.toString());
    // or, if the batch is your first transaction
    // const batchIndex = 1n;

    // Derive the PDA of the Squads Vault
    const [vaultPda] = multisig.getVaultPda({
        multisigPda,
        index: 0,
    });

    const instruction = SystemProgram.transfer({
        fromPubkey: vaultPda,
        toPubkey: member,
        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,
        multisigPda,
        vaultIndex: 0,
        transactionMessage: transferMessage,
        // Index of the transaction inside of the batch! Not globally. Starts at 1
        transactionIndex: 1,
        ephemeralSigners: 0,
        // Must be the member who created the batch
        member,
    });
}
```

## Error Handling

| Error | Cause | Solution |
| - | - | - |
| Invalid batch index | Wrong global batch index | Verify the batch exists at the specified index |
| Invalid transaction index | Wrong internal index | Use sequential indices starting at 1 |
| Proposal not draft | Proposal has been activated | Can only add to batches with draft proposals |

## See Also

* [Create Batch](/developers/typescript-sdk/instructions/create-batch)
* [Batch Account](/developers/typescript-sdk/accounts/batch)
* [Batch Reference](/developers/reference/accounts#batch)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.