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";asyncfunctionmain(member:PublicKey) {// Cluster Connectionconstconnection=newConnection("<your rpc url>");// If you've saved your createKey, you can define it as a static PublicKeyconstcreateKey=newPublicKey("<your createkey>")// Derive the multisig PDAconst [multisigPda] =multisig.getMultisigPda({ createKey, });// or// const multisigPda = new PublicKey("<your multisig key>");// Derive the PDA of the Squads Vaultconst [vaultPda] =multisig.getVaultPda({ multisigPda, index:0, });// Get deserialized multisig account infoconstmultisigInfo=awaitmultisig.accounts.Multisig.fromAccountAddress( connection, multisigPda );// Get the updated transaction indexconstcurrentTransactionIndex=Number(multisigInfo.transactionIndex);constnewTransactionIndex=BigInt(currentTransactionIndex +1);constto=newPublicKey("<>");consttransferInstruction=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 executeconsttestTransferMessage=newTransactionMessage({ payerKey: vaultPda, recentBlockhash: (awaitconnection.getLatestBlockhash()).blockhash, instructions: [transferInstruction], });constix=awaitmultisig.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