Skip to main content
@provablehq/shield-swap-sdk adds typed Shield Swap actions to a Veil client. Chain reads and writes sit on client. Indexed REST methods sit on client.api. Use the SDK when an application needs to sign Shield transactions without implementing record selection, program imports, swap planning, confidential addresses, or position math from scratch. These guides target SDK version 0.7.0.

Install

Local-key clients also need the network package and the SDK used for confidential-address derivation.

Create a local client

This example uses mainnet. Change loadNetwork("mainnet") to loadNetwork("testnet") for testnet. The Shield API host follows the client’s network, so shieldSwapActions({ api: {} }) selects the matching API without a hardcoded URL.
The default in-memory confidential-address store protects concurrent swaps made through one client. It disappears when the process exits. Bots and services should use fileBlindedIdentityStore so pending claims survive restarts.
Keep private keys, Provable credentials, API tokens, and confidential-address files out of source control.

Connect a wallet

The wallet holds keys and records and proves transactions. Pass Shield Swap’s algorithm grants when connecting, then extend the wallet client.
A connected wallet supplies record requests to transaction actions. The local-key client can find its own records through the configured scanner.

Authenticate the API

Pool and token discovery are public. Routes, balances, positions, swaps, and other account data require authentication and invited access.
authenticateShieldSwap() signs a challenge and stores the session on the API client. Long-running services can create an API token once and pass it as shieldSwapActions({ api: { apiToken } }) on later runs. See Authentication.

Read state

Use the API to discover markets and metadata. Read execution-critical pool state from chain before signing.
Token amounts use raw base units and bigint. Apply token decimals only when parsing user input or formatting output. Pool price and fee-growth values use Q128.128 fixed-point representation.

Resolve program imports

Shield Swap calls token programs dynamically. Write actions need the source for each token program plus the AMM’s declared imports.
Resolve imports once for a route or pool and reuse the map. Continue with SDK swaps or SDK liquidity. The package source and examples document the complete SDK surface.