@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_000nis 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
feePayerand a freshrecentBlockhash, then sign with the right keypair. Set the blockhash immediately before sending — one fetched earlier can expire. - Addresses are
PublicKeyfrom@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 aSubscriptionAuthority for this mint:
- If not: it includes the
initialize_subscription_authorityinstruction and passes S&A’sUNKNOWN_INIT_IDsentinel tocreate_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.
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 singleTransactionInstruction, 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_IDSUBSCRIPTIONS_PROGRAM_IDTOKEN_PROGRAM_IDASSOCIATED_TOKEN_PROGRAM_IDMAX_DESTINATIONS(4)UNKNOWN_INIT_ID(i64::MIN, as abigint)
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.buildExecutePullTransactionalready spreads its result onto the instruction.checkMintSupported(connection, mint)accepts every mint. This is where unsupported-mint rejection will live.
(1).png?fit=max&auto=format&n=qzWg2aQwcoMXkrks&q=85&s=7bd9594b6c05a51ce5a41a26f4cb7e42)
(1).png?fit=max&auto=format&n=qzWg2aQwcoMXkrks&q=85&s=f7ad867613529ca7109dfe0b0dabd815)