Quickstart

A 10 minute overview on how to interact with Squads Protocol using Typescript.

Set up your workspace (1 minute)

Important note: You can find the code for this quickstart guide here.

Let's set up a new Typescript project. First, create a new directory.

mkdir squads_quickstart
cd squads_quickstart

Now, create a new file named tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "esModuleInterop": true
  }
}

Add a package.json file and add this content

{
  "scripts": {
    "test": "npx mocha -r ts-node/register 'main.ts' --timeout 10000"
  },
  "dependencies": {
    "@solana/web3.js": "^1.73.0",
    "@sqds/multisig": "^2.1.3"
  },
  "devDependencies": {
    "@types/chai": "^4.3.3",
    "@types/mocha": "^10.0.6",
    "chai": "^4.3.6",
    "mocha": "^10.3.0",
    "ts-mocha": "^10.0.0",
    "typescript": "^4.8.3"
  }
}

Here, the main takeaway is that we are going to use the @sqds/multisig package.

Last but not least, create a main.ts file at the same location, and add this code:

Let's get to the code (8 minutes)

Create a multisig (2 minutes)

Let's set up a testing flow in which we're going to create a multisig, propose a new transaction, vote on that transaction and execute it.

First, let's add our first step: Setting up the multisig members and creating the multisig.

Create transaction proposal (2 minutes)

Now, let's create a transaction proposal. We want the multisig to send 0.1 SOL to the creator. For purposes of this tutorial, we first have to send that amount to the multisig, and can then create a message containing the instruction that needs to be executed.

Vote on the transaction proposal (2 minutes)

Let's now vote on the transaction proposal we just made using the two Keypairs we created at the start of this tutorial: creator and secondMember.

Execute the transaction (2 minutes)

Now the most important part, actually executing that transaction we proposed.

Start a local validator (1 minute)

Now that you have a completed flow, let's actually execute these transactions on chain. For the purpose of this tutorial, we are going to do so on a local Solana instance.

If you do not yet have the Solana CLI installed, please do so by reading the following guide.

Now, start up a local validator with the Squads V4 program preloaded.

Note: You will also have to clone the program config account from mainnet.

Set Your Environment to Devnet (Optional, 1 minute)

If you run into issues creating a local validator and cloning the necessary accounts, you can optionally use Solana's devnet cluster. This is a useful alternative because all needed accounts will already be available.

To switch to devnet, edit the connection variable you defined earlier in the guide:

When using devnet, you may run into rate limit issues when attempting to request an airdrop. To circumvent this, we can use the keypair from our Solana CLI, and manually fund any keypairs we create. To do this, we can refactor the beginning of our script to accomplish this:

and then add this snippet at the beginning of your first test:

Execute the script

Okay, let's execute the script and see what happens.

If you are encountering any issues here, try using another version of Node.js (above 20.xx). Additionally, switching SDK versions (to 2.1.1 or 2.1.0) may alleviate any ESM resoultion issues.

If you get a "fetch failed" error, make sure your local validator is running.

Visualize your transactions

Once the tests have passed, you can go to the Solana Explorer and visualize your transactions by pasting their signature in the search bar and modifying the cluster endpoint to the one you want (mainnet, devnet, localnet...).

What can I do from here?

Last updated