Create a Multisig

To create a multisig, first derive the address. The address is technically a PDA, and can be derived based off of the createKey. The createKey can be any public key (wallet, random, etc.), as long as its supplied as a PublicKey type.

Additionally, the create method will need an approval threshold and a list of keys to act as the members of the multisig (signers).

For example, to create a multisig based on a user's wallet address or a random key:

 // using a wallet to seed the multisig & address
 const createKey = wallet.publicKey;
 // or
 const createKey = anchor.web3.Keypair.generate().publicKey;
 
 // list of members/keys
 const membersList = [wallet.publicKey, otherKey1, otherKey2];
 // threshold
 const threshold = 2;
 
 // the multisig pda
 const multisig = await anchor.web3.PublicKey.findProgramAddress(
    anchor.utils.bytes.utf8.encode("squad"),
    createKey.toBuffer(),
    anchor.utils.bytes.utf8.encode("multisig")
 );
 
 // adjust to fit your Anchor provider or if using React useAnchorWallet() hook
 const creator = wallet.publicKey;
 
 // this will create a multisig with a threshold of 2/3, with three members
 await squadsProgram.methods.create(threshold, createKey, memberList)
          .accounts({
             multisig,
             creator,
           })
           .rpc();

Read the section on PDAs for more information about the multisig PDA.

Last updated