Skip to main content
This guide explains how to efficiently add multiple authorities to a Swig account in batch operations. This is particularly useful when you need to set up complex permission structures or onboard multiple users at once, saving on transaction fees and improving atomicity. You can find complete working examples in the Swig repository:
This example uses LiteSVM for testing and demonstrates advanced authority management patterns.

Why Batch Operations?

When setting up a Swig with multiple authorities, you have two options:
  1. Add authorities one at a time - Simple but requires multiple transactions
  2. Batch add authorities - More efficient, atomic, and cost-effective

Two Approaches to Batch Adding

Swig provides two methods for batch adding authorities:
  1. During Creation: Add multiple authorities when creating the Swig using getCreateSwigInstructionBuilder
  2. After Creation: Add multiple authorities to an existing Swig using getAddMultipleAuthoritiesInstructionBuilder
Let’s explore both approaches.

Approach 1: Adding Authorities During Swig Creation

When creating a Swig, you can chain .addAuthority() calls to add multiple authorities in the creation transaction. This is ideal for initial setup.

Key Differences from Basic Creation

Instead of getCreateSwigInstruction, use getCreateSwigInstructionBuilder which returns a builder that allows chaining.

Key Points

  • Use getCreateSwigInstructionBuilder instead of getCreateSwigInstruction
  • Chain .addAuthority() calls for each additional authority
  • Call .getInstructions() at the end to get all instructions
  • All authorities are added in a single atomic transaction

Approach 2: Adding Multiple Authorities to Existing Swig

Sometimes you need to add multiple authorities to an existing Swig. For this, use getAddMultipleAuthoritiesInstructionBuilder. This is particularly useful for:
  • Team onboarding - Adding multiple team members at once
  • Permission upgrades - Granting multiple new authorities simultaneously
  • Dynamic authority management - Responding to application events

Key Points for getAddMultipleAuthoritiesInstructionBuilder

  1. Fetch fresh Swig data - Always fetch the latest Swig state before adding authorities
  2. Need proper permissions - The signing role must have all or manageAuthority permission
  3. Chain additions - Call .addAuthority() for each authority you want to add
  4. All or nothing - The operation is atomic - all authorities are added or none

Advanced: Multi-Curve Authorities

Swig supports multiple cryptographic curves. You can mix Ed25519, Secp256k1 (Ethereum), and Secp256r1 (Passkeys/WebAuthn) authorities in a single Swig!

When to Use Each Approach

Summary

  • Two batching methods - Use builders for creation-time or post-creation batching
  • Atomic operations - All authorities are added together or none at all
  • Multi-curve support - Mix Ed25519, Secp256k1, and Secp256r1 authorities

Additional Resources