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