Skip to main content
@shugo-protocol/sdk builds the transactions for everything the CLI does, as plain functions you call from your own code. It never signs and never sends: every function returns an unsigned Transaction (or a single instruction) and leaves signing, fee payment, and submission to you. That’s deliberate — your agent framework already has opinions about key management and RPC handling, and the SDK shouldn’t override them.

Installation

Install the SDK alongside @solana/web3.js (peer dependency):

Conventions

  • Amounts are base units, as bigint. 25_000_000n is 25 tokens of a 6-decimal mint. The CLI converts from human-friendly decimals for you; the SDK does not. Read the mint’s decimals yourself if you need to convert.
  • Returned transactions are unsigned and incomplete. Before sending, set feePayer and a fresh recentBlockhash, then sign with the right keypair. Set the blockhash immediately before sending — one fetched earlier can expire.
  • Addresses are PublicKey from @solana/web3.js, a peer dependency.

High-level helpers

createPolicyAndDelegation

Builds the transaction that creates a policy and registers it as the delegatee on a real Subscriptions & Allowances delegation, in one atomic transaction. Signed by the human.

Parameters

Returns: { transaction, policy, delegation, subscriptionAuthority } — the unsigned transaction and the three addresses it creates or uses.

Behavior to know about

The function checks on-chain whether the human already has a SubscriptionAuthority for this mint:
  • If not: it includes the initialize_subscription_authority instruction and passes S&A’s UNKNOWN_INIT_ID sentinel to create_fixed_delegation. The authority’s generation ID is the slot it’s created in, which can’t be known before the transaction lands; the sentinel tells S&A to accept an authority created in the same slot.
  • If so: it decodes the existing authority, confirms it belongs to this human and mint, and passes its real init_id.

buildExecutePullTransaction

Builds the transaction an agent sends to pull funds through a policy. Signed by the agent.
It reads the live policy account to derive everything else execute_pull needs — the human, the mint, the S&A authority, the human’s token account, and the event authority. A caller only has to know the policy, the delegation, an amount, and a destination. policyAccount is the policy state the transaction was built against, which is useful for showing what’s about to be checked.

Instruction builders

Lower-level builders return a single TransactionInstruction, for when you’re composing your own transactions. Account orders match the program’s #[derive(Accounts)] structs exactly.

Reading state

Address derivation

Each PDA function returns [address, bump].

Constants

The SDK exports:
  • GUARD_PROGRAM_ID
  • SUBSCRIPTIONS_PROGRAM_ID
  • TOKEN_PROGRAM_ID
  • ASSOCIATED_TOKEN_PROGRAM_ID
  • MAX_DESTINATIONS (4)
  • UNKNOWN_INIT_ID (i64::MIN, as a bigint)

Extension points

Two functions exist today as deliberate no-ops, so that adding the missing support later changes one function each and nothing that calls them:
  • resolveExtraAccountsForMint(connection, mint) returns []. This is where Token-2022 transfer-hook accounts will be resolved. buildExecutePullTransaction already spreads its result onto the instruction.
  • checkMintSupported(connection, mint) accepts every mint. This is where unsupported-mint rejection will live.
See the FAQ for what each gap means in practice.