1. Creating a Swig
“A journey of a thousand steps starts with one Swig.” - Somebody
Before we begin our quest lets make sure you have the basics ready so lets set up a basic project, if you have already done this, feel free to move on. If you have not finished step 0 in this tutorial please go back and run through that as we refer back and depend on this step.
Now that you have your environment all setup and ready to role, make a new file called tutorial.ts
, make sure you are in the examples/transfer
folder. Don’t forget to start your validator with bun start-validator
Open that file up in your favorite editor, or AI overlord super virtual reality googles. Lets make a function called createSwigAccount
Example
Lets save this and get ready to run it, but before we do lets break it down step by step.
1. Import Required SDKs
Imports Solana primitives and essential utilities from the Swig SDK.
2. Generate a Unique Swig ID
Generates a secure 32-byte ID that uniquely identifies this Swig wallet instance. This ID is used to derive the PDA (Program Derived Address).
💡 This can really be anything, as long as it’s globally unique. You can even use other public keys, strings, or a boring old number if needed.
3. Derive the Swig PDA
Computes the wallet’s on-chain PDA using the generated ID. This is the unique address of the Swig account on Solana.
🧠 This is a standard Solana pattern—Swig just makes it easier.
4. Create the Root Role
Swig is role-based: it combines Authorities (who) and Actions (what) to determine permissions. This section builds the root role.
This sets up the root role. Since this is the root, it must have at least manageAuthority()
or all()
.
✅
manageAuthority()
is restrictive but safe.🚨
all()
gives full control—use carefully in production.
You can find all available action types in the Swig SDK docs. New types may be added over time.
Swig supports multiple Authority types—this example uses Ed25519Authority
, but others are available for different credentials or verification methods. These handle the Authentication half of Swig’s model. You can find all the types of authorities on the SDK Docs.
5. Create the Swig Account On-Chain
Creates the Swig account by sending a transaction to the Solana blockchain. The transaction must be signed by the user. In this case the payer of the transaction and the rent is the user, but you can also have a different fee payer for transaction for an example see this.
6. Simulate a Funded User
Creates a fresh Keypair and airdrops some SOL from the local validator so it can pay for the transaction.
7. Connect to the Validator
Creates a connection to the local Solana cluster. Ensure you’ve run:
This spins up a local testnet with the Swig programs deployed.
8. Log Success
Prints the address of the new Swig account in a colorized format.
Ready to run it?
Congratulations on your first Swig!