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

Create Vault Transaction

Add arbitrary transactions to execute through your multisig

Vault Transactions allow you to take actions from programs all across Solana, and execute them inside of your multisig.

To create one, you need the latest transaction index from your multisig account, a message with the instructions you want to execute, and the index of the vault you'd like to execute from. Additionally, you can also add n number of ephemeral signers, in case that extra signatures are required.

Example

import * as multisig from "@sqds/multisig";
import { PublicKey, Connection, 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>");
    
    // Derive the PDA of the Squads Vault
    const [vaultPda] = multisig.getVaultPda({
        multisigPda,
        index: 0,
    });
    
    // Get deserialized multisig account info
    const multisigInfo = await multisig.accounts.Multisig.fromAccountAddress(
      connection,
      multisigPda
    );

    // Get the updated transaction index
    const currentTransactionIndex = Number(multisigInfo.transactionIndex);
    const newTransactionIndex = BigInt(currentTransactionIndex + 1);
    
    const to = new PublicKey("<>");
    
    const transferInstruction = SystemProgram.transfer({
        // The transfer is being signed by the vault that's executing
        fromPubkey: vaultPda,
        toPubkey: to,
        lamports: 1 * LAMPORTS_PER_SOL
    });
    
    // Build a message with instructions we want to execute
    const testTransferMessage = new TransactionMessage({
        payerKey: vaultPda,
        recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
        instructions: [transferInstruction],
    });
    
    const ix = await multisig.instructions.vaultTransactionCreate({
        multisigPda,
        transactionIndex,
        creator: member,
        vaultIndex: 0,
        ephemeralSigners: 0,
        transactionMessage: testTransferMessage,
        memo: "Our first transfer!"
    });
}

Notes

  • Vault transactions are built with a TransactionMessage containing the instructions you want to execute

  • Proposal accounts must be created to successfully vote and execute vault transactions

PreviousCreate Config TransactionNextCreate Proposal

Last updated 7 months ago

For more information, see the section and .

reference
Vault Transaction