# Build with Nido Nido gives the people using your Stellar app a smart account they unlock with a passkey. These pages explain how your app works with that account, for developers and for the AI coding agents working with them. Page: /docs/ ## What Nido is, for an app A Nido account is a Soroban smart account: a contract with a C-address, not a classic G-address keypair. Its owner unlocks it with a passkey (Face ID, Touch ID, a security key), so there is no seed phrase and no browser extension. Nido's relayer pays to create the account. In this testnet tutorial, a new account arrives with 5 test XLM. Your contract doesn't need to know any of this. It calls `user.require_auth()` as usual, and the account decides whether to authorize. The one thing that changes for your app is how it gets a signature. Nido's passkey popup only signs calls on the account itself. To call your contract, the owner approves a **session** once: rules that let your app's own passkey call the functions you name, on the contracts you name, until an expiry, and optionally under a spending cap. After that the device asks for the app's passkey on each call, and the account checks every call against the rules. Nido's relayer submits the call and pays its fee. > These guides and the app template use Stellar **testnet**, at > [test.nido.fyi](https://test.nido.fyi). Nido also has a mainnet deployment at > [nido.fyi](https://nido.fyi); the tutorial's funding, contracts and fee > measurements are for testnet. Use throwaway testnet accounts for the examples. ## Start here The fastest working path is the [Nido app template](https://github.com/nidohq/scaffold-template), a [Scaffold Stellar](https://github.com/stellar-scaffold/cli) React app with Nido in the wallet picker and the session flow already built: ```sh stellar scaffold init --template nidohq/scaffold-template my-app ``` Then follow [Getting started](/docs/getting-started/). Today the template is the only published path from a Nido account into your own contract, because the session flow lives in its `app-lib/session.ts` rather than in a Nido SDK. ## The pages - [Getting started](/docs/getting-started/): from `init` to a passkey account and a first call signed with your app's passkey. - [Concepts](/docs/concepts/): smart accounts and passkeys, sessions, grants and spending caps, expiry, and who pays for what. - [Request a session](/docs/sessions/): grants with limits, what the owner sees on Nido's pages, and how to handle a refusal. - [Fees and storage](/docs/fees/): measured costs for accounts, grants and session calls. - [Troubleshooting](/docs/troubleshooting/): known pitfalls and what to do about each. - [For AI agents](/docs/ai-agents/): the rules in short form, how to check work against testnet, and the plain-text versions of these pages. ## What isn't available yet These pages describe what works today. Some things you might expect are not built yet, and the pages say so where they come up: - **Revoking a session.** A grant lasts until its expiry. - **A published Nido SDK for sessions.** The flow lives in the template's `app-lib/session.ts`. - **A mainnet walkthrough.** These guides use the template's testnet setup. ## Source - Nido: [github.com/nidohq/nido](https://github.com/nidohq/nido) - The app template: [github.com/nidohq/scaffold-template](https://github.com/nidohq/scaffold-template), with `NIDO.md` (for people) and `AGENTS.md` (for coding agents) - The session flow described here matches the template's [passkey-session update](https://github.com/nidohq/scaffold-template/commit/6f41265a4225703c057d6d04e07c3594a1a3972f): one approval for the grants, an app passkey prompt per call, and relayer-paid fees. - Perch, the policy layer Nido accounts enforce: [github.com/stellar-registry/perch](https://github.com/stellar-registry/perch) --- # Getting started Make an app from the Nido template, create a passkey account, approve a session once, and sign calls with the app's passkey, all on testnet. Page: /docs/getting-started/ ## Before you start You need: - Node 22.12 or newer - Rust, with the `wasm32v1-none` target (`rustup target add wasm32v1-none`) - The [Stellar CLI](https://developers.stellar.org/docs/tools/cli/install-cli) - A browser that supports passkeys, on `https://` or `localhost` The template installs its own copy of Scaffold Stellar, so you don't need a global one. ## 1. Make the app ```sh stellar scaffold init --template nidohq/scaffold-template my-app cd my-app npm run tools:scaffold # stellar-scaffold for this project, in .tools/ (seconds) npm ci # npm 11 prints allow-scripts warnings; they are harmless npm run doctor # checks tools, testnet, keys and clients, and says how to fix what's missing npm run clients:testnet # a client for the shared Guess the Number deployment npm run dev # open the URL it prints ``` `npm run clients:testnet` creates a throwaway deployer key on its first run and has Friendbot fund it. Keys and contract aliases stay in the project's `.stellar-config/`, not in your global `~/.config/stellar`. > **Run two apps? Give each its own port.** An app made with `init` keeps the > default `PORT=5173`. Session metadata lives in the browser storage of the > app's origin, which includes the port, so two apps on the same port share > session storage, and an app that moves to another port has no session. > Set a different `PORT` in each app's `.env`, and open it at `localhost`, > not `127.0.0.1`: passkeys need a hostname. ## 2. Create a Nido account Open [test.nido.fyi](https://test.nido.fyi) in the **same browser** you'll use for the app, choose **Get started**, then **Set up with your face**, and create the passkey when your device asks. Nido reserves the account's C-address, deploys the account through its relayer and funds it with 5 test XLM. It takes under a minute. You can also start from the app's Connect button, but creating the account first avoids a confusing step: see the next section. ## 3. Connect from the app In the app, press **Connect** and choose **Nido**. A popup on test.nido.fyi lists the accounts on this device. Choosing one shares only its address; nothing is signed. The app's header then shows the C-address and its XLM balance. > **"Wallet connection was cancelled or failed."** If you press Connect before > you have an account, the popup says "No accounts on this device. Create one > first". Following that link creates the account inside the popup, and when > you close it, the wallet picker reports a cancelled connection. Nothing went > wrong: press **Connect** again and choose the new account. ## 4. Approve the session The sample game, Guess the Number, takes 1 XLM for each wrong guess. Its gate explains the session and asks you to **Make a passkey for this app**. 1. Make the app's passkey when your device asks. This is separate from your Nido account's passkey. Its private key stays in the authenticator; the app stores only its public key, credential id and session metadata. 2. Press **Approve with Nido (2 rules, one confirmation)**. One popup shows both rules for 24 hours: `guess` on the game, without a cap, and `transfer` on XLM, capped at **2 XLM per day** and paying **only the game**. The template sends `limit=none` for `guess`, so no uncapped-spending checkbox is needed for that rule. 3. Review both rules and confirm once with your **Nido account's passkey**. Nido's relayer applies them together and closes the popup. 4. Back in the app, the game is playable. The app passkey needs no Friendbot funding: Nido's relayer pays the transaction fees. There are two rules because the call authorizes both the game and XLM. They share one approval. See [Request a session](/docs/sessions/) for the API. ## 5. Make a call with the app's passkey Guess a number and answer your device's **app passkey** prompt. No Nido approval page opens for each guess. The app signs the authorization and Nido's relayer submits it. A wrong guess moves 1 XLM from your account to the game and shows the transaction hash. After two wrong guesses, the sample shows **Cap reached until ≈ …** and disables Submit. It reads the spending record before requesting another passkey signature; the account also enforces the cap during simulation. A refused call sends nothing and costs nothing. Renewing the same rules keeps their spending record, so re-approving does not reset a spent cap. That refusal is the account enforcing the rule you approved. The app can't get around it, and nobody holding the session key can either. ## 6. Use your own contract The template's `NIDO.md` walks through it. In short: 1. Write the contract in `contracts/`. In each function a user calls, `user.require_auth()` comes first. 2. Find its grants: assert `env.auths()` in a unit test. Each contract in that list needs one grant (see [Concepts](/docs/concepts/#grants-and-spending-caps)). 3. List it in `scaffold.yml` under `contracts:`. 4. `npm run deploy:testnet` deploys it, pins the new contract ID under `testnet:` and writes its client. 5. Call it from React with `submitCall`, inside a `SessionGate` that asks for those grants. [Request a session](/docs/sessions/) shows the pattern. From a checkout of the template, `npm run new-app -- ../my-app --blank` starts an app with a one-function starter contract in place of the sample, its own package name, deployer identity and dev-server port. ## Next - [Concepts](/docs/concepts/) explains what you just approved. - [Fees and storage](/docs/fees/) explains what each step cost. - [Troubleshooting](/docs/troubleshooting/) covers what can go wrong on the way. --- # Concepts What a Nido account is, why your app needs a session to call your contract, what a grant allows, when it ends, and who pays for each step. Page: /docs/concepts/ ## Smart accounts and passkeys A Nido account is a Soroban smart account: a contract at a C-address, built on [Perch](https://github.com/stellar-registry/perch) and OpenZeppelin's `stellar-accounts`. Its owner holds a passkey, a P-256 key that stays on their device or in their password manager. The account checks the passkey's WebAuthn signature on chain, through a verifier contract, so Nido's servers never see or hold a key that can move funds. What that means for your app: - **The address is a contract.** Tools that expect a G-address can trip on it. A C-address can't be the source of a transaction or sign a classic Stellar operation; it authorizes Soroban contract calls. The template's `isSmartAccount(address)` tells the two apart, and `transactionSource(address)` leaves the source empty for a C-address so the generated client simulates with a placeholder source. - **Your contract doesn't change.** It calls `user.require_auth()` and the account decides whether to authorize. - **The owner's passkey belongs to the account's own subdomain**, `.test.nido.fyi` in this testnet guide. That is why Nido's signing and grant pages open there, in a popup or a redirect, and not inside your app. - **The owner can recover the account** if they lose the passkey, through friends they trust, a recovery kit, or both. See [How recovery works](/how-recovery-works/). ## Why the passkey popup can't call your contract The passkey signs under the account's first rule, **admin**, and that rule only covers calls on the account itself, such as a change to its policy. If your app asks Nido's sign popup to authorize a call into your contract, the account refuses it: | Code | Meaning | | --- | --- | | `#3002` | No rule covers the call (one contract in the call) | | `#3014` | A contract in the call has no rule (several contracts) | So an app acts for a Nido account through a **session**. ## Sessions and app passkeys A session is a set of rules in the account's policy that names your app's passkey, separate from the owner's Nido passkey. 1. The device makes a passkey on the app's own origin. Its private key stays in the authenticator; the app stores its public key and credential id. 2. The owner approves the rules together on Nido's grant page with their **Nido passkey**. Each rule names the app passkey as an **External signer**, checked by the WebAuthn verifier, and limits the contracts, functions, expiry and spending it may authorize. 3. For each later call, the device asks for the **app passkey**. The app signs the account's authorization entry under the approved rules; Nido's relayer submits it and pays the fee. The account checks the rules on every call. The app passkey never holds the user's money. Payments come from the account and the token grant enforces its cap and recipient restriction. - **Only public session data lives in `localStorage`.** Reading that data does not reveal a signing key. Code controlling the app can still request a device signature, so caps and recipients bound what an approval permits. - **The origin includes the port.** A dev server that moves from port 5173 to 5174 has no session there, and two apps on one port share one. - **One app passkey per account and origin.** Several gates in one app share it, and each asks only for the grants it lacks. - **Use a hostname.** Open local apps at `localhost`, not `127.0.0.1`, so the browser can create and use passkeys. ## Grants and spending caps A grant is one rule the owner approves. In the template it looks like this: ```ts const grants: Grant[] = [ { target: guessTheNumber.options.contractId, // the one contract functions: ["guess"], // every function when omitted duration: "24h", // "24h" | "7d" | "30d" label: "guess", // the rule's name, at most 20 bytes }, { target: xlmTokenId, // a capped grant names the token functions: ["transfer"], duration: "24h", limit: { amount: "2", period: "day" }, // "day" | "week" | "30d" to: guessTheNumber.options.contractId, // may pay only the game label: "guess-xlm", }, ] ``` The rules that follow from how the account checks a call: - **One grant per contract the account authorizes in the call.** That is the root call plus every sub-call that needs the same account's authorization, such as a token `transfer` from the user. Guess the Number needs two: the game, and the XLM token it moves. To find yours, assert `env.auths()` in a unit test; each contract in that list is a grant. - **Keep `require_auth()` at the root.** Call `user.require_auth()` in your contract's function before it moves the user's tokens. Relying on the token's own check instead makes the authorization non-root, and simulation refuses it: "authorization not tied to the root contract invocation". - **A `limit` caps cumulative `transfer` amounts, and only on a grant whose `target` is that token.** A cap on any other contract doesn't limit what that contract moves. The period is a rolling window of ledgers: `day` is 17,280 ledgers, about 24 hours at five seconds a ledger. - **Restrict a payment's recipient with `to`.** On a grant whose functions are exactly `["transfer"]`, it names the only address that may be paid. Without it, the key can pay any address up to the cap. Rules are checked per call, so a token grant can authorize a transfer outside your game's call too; `to` keeps that transfer restricted to the game. - **The template sends an uncapped grant as `limit=none`.** Nido skips the uncapped-spending checkbox when its explicit `functions` list names no token function, such as `guess`. Other uncapped grants require the owner to choose a cap or tick "Let this key spend without any cap". - **The same label replaces the rule.** Asking again with an existing label changes or renews that rule in place. Patterns that work: - **An action that moves no money** (claim, vote, check in): one grant on your contract, no cap. - **A capped payment** (tip, buy, a game stake): two grants, your contract plus the token with a `limit` and `to` set to your contract, approved together. - **Shared funds** (a group pot): your contract holds the money and pays out when enough members approve. Each member uses their own Nido account. - **Limits for someone else** (an allowance): a cap limits a key, not the account's owner. Keep custody in a contract the limited person doesn't administer. - **Time locks:** a rule's expiry stops a key; it doesn't delay a withdrawal. Put unlock dates in your contract. ## Expiry, renewal and revoking Every grant ends at its expiry. The template offers `24h`, `7d` and `30d`, and Nido turns them into a ledger number when the owner approves. When a grant runs out, the account refuses the next call (`#3002` or `#3016`) and the template's gate shows **Renew**, which asks for the same labels again. Revoking a session before it expires is **Not available yet**. Plan as if every grant lasts until its expiry, and pick the shortest duration that works for your app. Nido's grant page also offers "Never (until revoked)"; the template leaves it out on purpose, and so should you until revoking works. The template's **Forget it** deletes this browser's session metadata. The device may still list the app passkey, and its rules stay on chain until expiry. Making a new app passkey and approving it with the same labels replaces those rules, so the old key no longer satisfies them. Renewing the same capped rules preserves their spending record. ## The relayer, and who pays for what Nido runs a relayer that pays the fees for the transactions Nido's pages submit. It pays out of one daily budget shared by everyone on testnet, counted by each transaction's fee bid rather than the fee it was finally charged. | Step | Who pays the fee | How it's sent | | --- | --- | --- | | Create an account | Nido's relayer | Nido's account page | | Apply a grant | Nido's relayer | Nido's grant page | | A call your app makes with a session | Nido's relayer | Your app signs with its passkey, then calls the relayer | | A call through Nido's sign popup | Nido's relayer | Nido submits it and returns the hash | | Tokens your contract moves | The account | Counted against the grant's cap | The current template uses passkey signatures in ordinary authorization entries, which the relayer accepts. A custom CAP-0071 delegated-key flow using `AddressWithDelegates` is different and needs its own submission path. [Fees and storage](/docs/fees/) has the measured amounts, and [Troubleshooting](/docs/troubleshooting/#nido-says-it-couldnt-confirm-what-happened) covers what happens when the relayer's budget runs out. ## Without the template To add Nido to the wallet picker of an app you already have, use the [Stellar Wallets Kit module](https://github.com/nidohq/nido/tree/main/packages/stellar-wallets-kit-module) and the [integration guide](https://github.com/nidohq/nido/blob/main/docs/ADD-NIDO-TO-DAPP.md). That gets you connect, and signing for calls on the account itself. When Nido's popup signs a transaction, Nido submits it through its relayer and returns the transaction hash, so your app must not broadcast it again. For calls into your own contract you need the session flow, which today lives only in the template's `app-lib/session.ts`. A published Nido SDK for it is **Not available yet**. [Request a session](/docs/sessions/#nidos-grant-page-parameters) documents the grant page's parameters if you build it yourself. --- # Request a session Ask a Nido account for the grants your app needs, with limits, explain them to the owner, and turn every refusal into a sentence a person can act on. Page: /docs/sessions/ ## The call site Everything below comes from the template's `@stellar-scaffold/app-lib` (`app-lib/` in your app), except `SessionGate`, which is a React component in `app/src/components/`, and your contract's generated client. ```tsx import { describe, isOverCap, submitCall, xlmTokenId, type Grant, } from "@stellar-scaffold/app-lib" import { myContract } from "@stellar-scaffold/app-lib/clients" import { useState } from "react" import { useWallet } from "../hooks/useWallet" import { SessionGate } from "./SessionGate" // Your contract's error codes as words (or your generated client's `Errors`) const errors = { 1: "Sold out", 2: "Already bought" } const dailyCap = 2 // One grant per contract the call authorizes for the user const grants: Grant[] = [ { target: myContract.options.contractId, functions: ["buy"], duration: "24h", label: "my-app", }, { target: xlmTokenId, functions: ["transfer"], duration: "24h", limit: { amount: String(dailyCap), period: "day" }, to: myContract.options.contractId, label: "my-app-xlm", }, ] export const Buy = () => { const { address } = useWallet() const [message, setMessage] = useState() const onClick = async () => { if (!address) return try { // No await before submitCall: Nido's popup needs the click's gesture const { result, hash } = await submitCall(address, (publicKey) => myContract.buy({ user: address }, { publicKey }), ) setMessage(`Done: ${String(result)} in ${hash}`) } catch (error) { setMessage( isOverCap(error) ? `That's the ${dailyCap} XLM a day you allowed. Nothing was sent.` : describe(error, errors), ) } } return ( Approve this app once and it can buy for you for 24 hours, spending at most {dailyCap} XLM a day, only to this contract. Your device asks for the app's passkey on each purchase. Nido shows both rules and you confirm them once: the first allows only buy; the second caps and restricts the XLM.

} > {message &&

{message}

}
) } ``` `submitCall(address, build)` builds the call with a transaction source a C-address can use, then submits it the right way for the connected wallet: - a classic G-address wallet signs and sends it; - a Nido account with an approved session: the device signs with the app's passkey (one prompt), and Nido's relayer submits it (`submitWithSession`); - a Nido account without one: Nido's sign popup, which only covers calls on the account itself, so a call into your contract is refused (`#3002` or `#3014`). It resolves `{ result, hash }` once the transaction is confirmed. The parts are exported too (`reserveSigningPopup`, `transactionSource`, `submitContract`) if you need your own flow. Calls take several seconds. Pass `{ onStage: setStage }` as `submitCall`'s third argument to show preparation, passkey, sending and confirmation progress with the template's `Pending` component, and disable the action while it runs. ## What SessionGate shows `SessionGate` compares the `grants` you pass with what the account has approved for this app's passkey: target, functions, cap, recipient and expiry. It shows its children to classic wallets right away, and to a Nido account once its approvals cover `grants`. Until then it shows one of: | State | What the owner sees | | --- | --- | | No app passkey yet | Your `explain` text and **Make a passkey for this app** | | Passkey made, grants needed | **Approve with Nido (N rules, one confirmation)** | | A grant changed (new target, function or cap) | "This needs more than you approved for this app so far." and **Approve** | | A grant expired | "This app's approval expired." and **Renew with Nido** | | Making the passkey | "Waiting for your passkey: your device makes one for this app…" | | Sent to Nido, no answer recorded | **Check again**, **Ask Nido again**, **Start over** | N is the number of grants still missing. The template sends grants with the same duration together, in one popup and one passkey confirmation (at most 8 per request). Use a shared duration for a gate's grants; grants with a different duration wait for a later request. With `actionsOnly`, the children stay visible and only their buttons and inputs wait for approval. Several gates in one app share one passkey. Each asks only for the grants it lacks. A redeployed contract gets a new ID, so a gate whose grant targets it asks again. ## Write the explanation The owner reads your `explain` text before Nido's pages, and Nido's pages show the rule's terms, not your app's reasons. Say: - what the app will do (the functions, in plain words); - for how long (the `duration`); - the most it can spend, what one action costs, and whom it may pay (`to`); - that each call asks for the app's passkey; - why one rule has no cap, if one doesn't. The template sends it as [`limit=none`](#nidos-grant-page-parameters): Nido skips the checkbox when the grant names no token function. Other uncapped grants ask the owner to choose a cap or accept uncapped spending explicitly. ## What the owner sees on Nido The app sends the owner to `https://.test.nido.fyi/security/delegate-doc/`. For each grant in the request, that page shows: - the contract and the app's key; - the functions the key may call; - the expiry, which the owner can change; - the spending cap in XLM ("Up to 2 XLM per day"), prefilled from your `limit`, or the "no cap" checkbox; a `limit=none` grant that names no token function reads "No cap — allows no token functions" instead; - for a grant that may call `transfer`, whom it pays: the one `to` address, or "Any address"; - what changes in the account's policy document, and the document itself. **Review & continue** opens Nido's signing page, the owner confirms with their passkey, and Nido's relayer applies the change. Then Nido hands `?delegation=ok` back to your app (see [the return](#nidos-grant-page-parameters) below). **Cancel** returns `?delegation=cancelled`: the template keeps the app passkey and anything already approved, and the gate asks again next time. Nido's grant page can take up to 8 grants in one request and install them all with one passkey confirmation. The template uses this for its two-grant sample. ## When the account says no The account checks every session call against its rules while the call is simulated, before your app sends anything. A refused call costs nothing. `describe(error, contractErrors)` turns each refusal into a sentence: | Code | Cause | `describe` says | | --- | --- | --- | | `#3221` | The call would go over a grant's cap | "Your account refused: this would go over the spending cap you gave this app." | | `#3002`, `#3016` | No rule covers the call, or it expired | "…no approved rule covers this call for this app (it may have expired)." | | `#3014` | The call touches a contract the app has no rule for | "…the call touches a contract the app has no rule for." | | `FEE_LIMIT_EXCEEDED` | Nido's relayer budget is used up | "Nido's free transaction budget is used up for now, so nothing was sent." | | `POOL_CAPACITY` | Nido's relayer is busy | "Nido's relayer is busy, so nothing was sent. Try again in a minute." | | `Error(Contract, #n)` | Your contract's own error | "The contract refused: " plus the text from `contractErrors` | Pass a table of your contract's error codes as `contractErrors` (your generated client's `Errors` table, or your own) so they read as words. Use `isOverCap(error)` when you want to name the cap and say when it resets, as in the example above; it recognises `#3221` before and after `describe` has turned it into a sentence. The template also reads spending records before asking the device to sign. `CapReachedError` carries an `until` time, and `capReachedUntil` lets a screen disable its action and show when the cap frees up. On-chain simulation still enforces the cap; a browser precheck does not replace it. `#3014` on a call that should be covered usually means a missing grant: a sub-call, such as the token `transfer`, needs a grant of its own. The template also stops before sending when no rule for this key covers a contract in the call, and names the contract. ## When an approval doesn't land Applying a grant goes through Nido's relayer, which can refuse or time out (see [Troubleshooting](/docs/troubleshooting/#nido-says-it-couldnt-confirm-what-happened)). The account's installed rules are the truth, so the template recovers from the app: 1. The owner goes back to the app. The gate says Nido hasn't confirmed the grant yet. 2. **Check again** reads the account's `installed_rules` and records any grant that landed, with its real expiry. 3. If nothing landed, **Ask Nido again** reuses the same app passkey. If the relayer budget is used up, wait and try later. The template can record `?delegation=error&code=…`, but Nido's grant page sends only `ok` and `cancelled` today. A structured grant error return is **Not available yet**. Session-call relayer errors already reach `describe` in the app. ## Nido's grant page parameters If you build the session flow yourself instead of using the template, this is the request Nido's grant page takes. Open `https://.test.nido.fyi/security/delegate-doc/` with the account's C-address in lower case as the subdomain, and these query parameters. Every request names one key, one duration and one return trip: | Parameter | Required | Value | | --- | --- | --- | | `origin` | Yes | Your app's origin (`https://…` or `http://localhost:…`) | | `return` | Yes | Where to send the owner back; must be on `origin` | | `signer` | One of the two | A delegated key your app holds: its address (`G…` or `C…`) | | `pubkey` | One of the two | Your app's passkey: the 65-byte SEC1 uncompressed P-256 public key, in hex (`04…`, no `0x`). A `credential_id` parameter rejects the request; keep the credential ID in your app | | `duration` | No | `24h`, `7d`, `30d` or `none`; `30d` when absent. Every grant shares it | Each grant is one rule, with these fields: | Field | Required | Value | | --- | --- | --- | | `target` | Yes | The contract (`C…`) the key may call | | `functions` | No | Comma-separated function names; every function when absent | | `limit` | No | A cap on `transfer` amounts in decimal XLM, or `none` | | `limit_period` | No | `day`, `week` or `30d`, only with a decimal `limit`; `day` when absent | | `to` | No | The only address (`G…` or `C…`) the grant's `transfer` may pay; only when `functions` is exactly `transfer`. Without it, a transfer grant can pay any address, up to its cap | | `label` | See below | The rule's name. The same name replaces that rule | For one grant, pass the fields as plain parameters (`target=…&functions=…`); `label` defaults to `session`. For several, pass each as `grant..`, numbered from 0 with no gaps, at most 8 grants. Each then needs its own `label`, and the plain grant fields may not appear alongside. Nido installs them all in one policy-document update (one `apply_doc`), with one passkey confirmation. Without `limit`, the owner chooses between a cap and ticking "Let this key spend without any cap". `limit=none` declares the rule uncapped and skips that tick, but only when the grant lists its `functions` and none of them is a token function (`transfer`, `transfer_from`, `approve`, `burn`, `burn_from`, `mint`, `clawback`, `set_authorized`, `set_admin`). Any other `limit=none` grant is shown as one without `limit`. A game whose `guess` moves a 1 XLM stake from the player, approved with one confirmation: ```text ?origin=https://game.example&return=https://game.example/play &pubkey=04…&duration=24h &grant.0.label=guess&grant.0.target=CGAME…&grant.0.functions=guess &grant.0.limit=none &grant.1.label=guess-xlm&grant.1.target=CXLM…&grant.1.functions=transfer &grant.1.limit=2&grant.1.limit_period=day&grant.1.to=CGAME… ``` A malformed value of a known parameter (`duration`, `signer` or `pubkey`, or a grant's `target`, `limit`, `limit_period` or `to`), or an unknown `grant..` key, rejects the whole request, so a bad cap can't turn into an uncapped grant. Any other unknown parameter is ignored: a typo such as `limit_peroid=week` is dropped and the default (`day`) applies. Avoid `duration=none`: revoking is not available yet, so such a rule would never end. The answer is `?delegation=ok` or `?delegation=cancelled`. Opened as a popup, the page (and the signing page after it) posts `{ source: "nido-wallet", search: "?delegation=ok" }` to the opener, targeting your `origin`, and closes. Opened as a page, it redirects to the return URL with that query added. Treat `ok` as "the page finished", and read the account's `installed_rules` to see what landed. The template uses `pubkey`, keeps the credential id locally for WebAuthn, and omits `credential_id` from the request. For later calls, it reads the installed rules and policy document, selects rules for the contracts and functions being authorized, and signs the account's authorization digest with the app passkey. It reads `capabilities().auth_digest` to choose the digest scheme (`addr_oz_v1` or the older `oz_rule_ids`). The WebAuthn assertion and rule ids go into an ordinary authorization entry, which is simulated before the app hands it to Nido's relayer. The template's `submitWithSession` in `app-lib/session.ts` is the complete example. `signer=` is a separate delegated-key path. A CAP-0071 `AddressWithDelegates` entry needs delegated signatures and a compatible submission path; do not substitute it for the template's passkey flow. --- # Fees and storage What each step costs on testnet, who pays it, and why the first call with a new session costs more than the ones after it. Page: /docs/fees/ ## Who pays | Step | Paid by | Historical testnet measurement (October 2026) | | --- | --- | --- | | Create an account | Nido's relayer | About 1.4 XLM | | Apply a first grant | Nido's relayer | About 4.5 XLM bid | | Apply a later grant, with a cap | Nido's relayer | About 2.7 XLM bid | | First call with a passkey session | Nido's relayer | About 0.565 XLM on October 23 | | Later passkey session calls | Nido's relayer | About 0.035 XLM on October 23 | | A call the account refuses | Nobody | Free: refused in simulation, nothing sent | | Tokens your contract moves | The account | Whatever the call moves, counted against the cap | 1 XLM is 10,000,000 stroops. These are measurements from real testnet runs, not quotes: fees on Stellar depend on network load and on how much the transaction reads, writes and stores. The template's [recorded testnet runs](https://github.com/nidohq/scaffold-template/blob/6f41265a4225703c057d6d04e07c3594a1a3972f/NIDO.md#verified-live-on-testnet) also saw a first guess cost about 3.3 XLM, later guesses 0.2 XLM, and approval 44 XLM under surge pricing on October 24. Use these as dated observations, not expected fees. They do not describe mainnet costs. ## Account creation and grants Nido's relayer pays for these out of a daily budget shared by everyone on testnet. The budget counts each transaction's **fee bid**, the most it offered to pay, not the fee it was charged in the end. That is why the grant rows above say "bid". A first grant costs more than later ones because it writes the account's policy document for the first time. If the shared budget is used up, the relayer refuses with `FEE_LIMIT_EXCEEDED` and nothing is sent. See [Troubleshooting](/docs/troubleshooting/#nido-says-it-couldnt-confirm-what-happened). ## Session calls The current template signs with an app passkey and Nido's relayer pays the fee for every submitted session call. The app passkey needs no funding. These calls share the relayer's testnet budget with accounts and grants. **Storage rent** can dominate a session call's cost. Soroban charges rent to keep persistent storage entries alive, and a transaction that extends an entry pays for the extension. Inclusion fees can also rise with network load. An earlier walkthrough using the former delegated-key session flow measured about **0.53 XLM** for its first call, almost all rent. That call extended six persistent entries to about 30 days: - on the account: two context rules, two policy entries and one signer entry, for the two rules a capped payment needs; - on the spending-limit policy contract: the spending tracker for the account. Later calls in that walkthrough cost about **0.034 XLM**, about 0.0325 XLM of it rent. Each spend grew the spending tracker's history, making the entry more expensive to keep alive. The remaining fee covered resources and inclusion. The current passkey flow has different signer and policy entries; this breakdown explains the earlier measurement, not its exact footprint. Those numbers come from a session with two grants, one of them capped. Yours will differ with the number of rules in the session and whether one is capped. Plan for this when you price an action: - Storage rent can be large next to a small payment, even when the relayer sponsors it. Reusing approved rules avoids needless policy writes. Choose the shortest approval duration that works for the app. - A call the account refuses, for example over the cap, is caught in simulation and costs nothing. - Your contract's own storage is extra. The sample game stores nothing per guess; the only temporary entry a guess writes is the authorization nonce. ## Custom submission paths An authorization signature does not choose the transaction's fee payer, so a custom integration can submit authorized calls with a funded transaction source. That is separate from the current template's relayer flow. Nido's grant page does not hand a signed approval back to the app for self-submission; that handoff is **Not available yet**. --- # Troubleshooting Known pitfalls when building a first app on Nido, what causes each one, and what to do. Page: /docs/troubleshooting/ ## Connecting ### The wallet picker says "Wallet connection was cancelled or failed." You pressed Connect before you had a Nido account, followed "Create one first" in the popup, created the account there, and closed the popup. The wallet picker reports the closed popup as a cancelled connection. Nothing went wrong: press **Connect** again and choose the new account. To avoid it, create the account at [test.nido.fyi](https://test.nido.fyi) first, in the same browser. ### Nido says "No accounts on this device" Nido's connect popup lists the accounts created or opened in this browser. Create one, or open the account you have in this browser first. A passkey works only in browsers that support passkeys, on `https://` or `localhost`, and not inside in-app browsers such as a social app's link viewer. ### Account creation says "Too many transactions queued" Nido's relayer was busy (`POOL_CAPACITY`), and nothing was sent. Wait a minute and try again. Keep the page open until it says your Nido is ready. ## Approving a session ### Nido says it couldn't confirm what happened Applying a grant goes through Nido's relayer. When the relayer refuses or times out, Nido's signing page currently shows the same message for every case: "We couldn't confirm what happened to this transaction on-chain… retrying could pay twice". The cases differ: | What happened | Relayer answer | Did the grant land? | | --- | --- | --- | | The shared daily budget is used up | 429 `FEE_LIMIT_EXCEEDED` | No | | The relayer is busy | 503 `POOL_CAPACITY` | No | | The relayer timed out after submitting | 504 | Sometimes | What to do: 1. Close Nido's popup to return to the app. If the browser opened Nido as a full page instead, use Back. 2. Press **Check again** on the template's gate. It reads the account's rules on chain and records a grant that landed. 3. If nothing landed, press **Ask Nido again**. It reuses the app's key. If the budget is used up, try again later. Don't retry blindly from Nido's page. The account's installed rules are the truth: see [Check what an account has approved](#check-what-an-account-has-approved). ### Making the app passkey seems to do nothing The gate first asks the device to make a passkey for this app. Complete or cancel that device prompt before trying again. Use `https://` or `localhost`, not a local IP address. No Friendbot funding is needed for the app passkey. ### Two rules, one confirmation Each contract the account authorizes needs a grant. The current template sends grants sharing a duration together, so the sample shows **Approve with Nido (2 rules, one confirmation)**. Making the app passkey is a separate device ceremony, and each later call asks for that app passkey. If an older checkout asks once per rule, update it to the template's passkey session flow. ### Nido asks to "spend without any cap" on a rule that can't spend The template sends a grant without a cap as `limit=none`. Nido skips the tick only if its explicit `functions` list names no token function, and shows "No cap — allows no token functions". A request that omits `limit`, omits the function list, or includes a token function still asks the owner to choose a cap or accept uncapped spending. If the call moves tokens, cap the grant whose `target` is the token and restrict its recipient with `to`. ### The owner cancelled Nido returns `?delegation=cancelled`. The template keeps the app passkey and anything already approved, and the gate asks again. ## Making calls ### `#3002` or `#3014` through Nido's popup Nido's passkey popup can't authorize a call into your contract: the passkey's rule covers only calls on the account itself. Ask for a session and call through `submitCall` inside a `SessionGate`. See [Concepts](/docs/concepts/#why-the-passkey-popup-cant-call-your-contract). ### `#3014` with an approved session The call touches a contract the session has no grant for, often a token `transfer` your contract makes from the user. Add a grant for that contract. Assert `env.auths()` in a unit test to list every contract a call needs. ### `#3002` or `#3016` with an approved session The rule expired, or the session doesn't cover this function. The template's gate shows **Renew** when a grant has expired. A redeployed contract has a new ID, so the old grant no longer covers it, and the gate asks again. ### `#3221`, over the cap The call would go over the grant's spending cap. Nothing was sent and it cost nothing. The template checks spending before prompting (`CapReachedError`), and the account also enforces it in simulation (`#3221`). Use `isOverCap(error)` to identify the refusal and `capReachedUntil` to display when the cap frees up. A `day` cap is a rolling window of 17,280 ledgers, about 24 hours. Re-approving the same rules preserves their spending record. ### Simulation says "authorization not tied to the root contract invocation" Your contract moves the user's tokens without calling `user.require_auth()` itself, so the token's check is the account's only authorization, and it isn't at the root of the call. Call `user.require_auth()` first in the function, and ask for one grant per contract. ### The session disappeared The session metadata lives in your app origin's `localStorage`, and the origin includes the port. A dev server that started on another port, a different browser profile, or cleared site data has no session metadata, even if the device still lists the passkey. Keep `PORT` fixed (the template sets `strictPort`) and approve again on the new origin. Grants also end at their expiry: 24 hours for the sample. ### Nido's popup was blocked Browsers allow a popup only during a click. Building a call simulates it over the network first, which loses the click. Call `submitCall` before any other `await` in the handler; it reserves the popup up front. ### A transaction hash came back from Nido's popup If you use Nido's wallet module directly: when Nido's popup signs a transaction, Nido submits it through its relayer and returns the hash. Don't broadcast it again. ### Revoking a session **Not available yet**. A grant lasts until its expiry. The template's **Forget it** deletes only this browser's session metadata; the passkey may remain on the device and the rules stay on chain. Making a new app passkey and approving it with the same labels replaces those rules, so the old key no longer satisfies them. ## Building and deploying ### `Error(Context, InvalidAction)` after deploying The contract was built with a plain `stellar contract build`, which compiles for the local network: `stellar_registry::import_asset!("xlm")` bakes that network's XLM contract into the wasm. Build through Scaffold (`npm run deploy:testnet`). To recover, run `cargo clean -p --target wasm32v1-none --release` and deploy again. ### Scaffold compiles but writes no clients Older `stellar-scaffold` releases ignore the template's `scaffold.yml` without an error. Run `npm run tools:scaffold` for the tested version, and `npm run doctor` to check. ### Harmless warnings - `npm warn allow-scripts` during `npm ci`: nothing in the template needs those install scripts. - "An identity with the name … already exists": Scaffold checks for the deployer on every build. ## Check what an account has approved The account's rules are the source of truth. From the template: ```sh npm run stellar -- contract invoke --id --network testnet --send=no -- installed_rules ``` The owner can also open their account at `https://.test.nido.fyi`, where the Policy page shows the policy document and every rule in it. --- # For AI coding agents What a coding agent building on Nido needs to know, how to check its work against testnet rather than mocks, and where to get these docs as plain text. Page: /docs/ai-agents/ ## Plain-text entry points - [`/docs/llms.txt`](/docs/llms.txt): an index of these pages with one line each. - [`/docs/llms-full.txt`](/docs/llms-full.txt): every page in one Markdown file. Load this instead of crawling the HTML. - In an app made from the template: `AGENTS.md` at the repo root states the same rules for the template's code, and `NIDO.md` explains them for people. The template's tests check that the two agree on commands and the call pattern. Paths in these files are on the host you fetched them from: `https://test.nido.fyi` for testnet. ## The rules - **The tutorial and template use testnet.** Use throwaway testnet accounts for these examples. Nido's mainnet deployment is separate; do not point the template's testnet contracts, RPC or funding flow at it. - **The passkey popup can't call your contract.** It signs under the account's admin rule, which covers only calls on the account itself; a call into another contract is refused with `#3002` (one contract) or `#3014` (several). Use a session. - **One `Grant` per contract the account authorizes in the call**: the root call plus every sub-call that needs the same account's authorization, such as a token `transfer`. Derive the list by asserting `env.auths()` in a unit test. - **`user.require_auth()` at the root** of every function a user calls, before it moves the user's tokens. Otherwise simulation refuses with "authorization not tied to the root contract invocation". - **`limit` caps cumulative `transfer` amounts, only on a grant whose `target` is that token** (`xlmTokenId` for XLM). The template sends uncapped grants as `limit=none`; Nido skips the checkbox when the explicit `functions` list names no token function. Use **`to`** on a transfer-only grant to restrict the recipient; otherwise it can pay any address up to the cap. - **The template sends grants together**, using `pubkey=` and `grant..` for one confirmation. Give a gate's grants the same duration, with at most 8 in a request ([parameters](/docs/sessions/#nidos-grant-page-parameters)). - **`label` is at most 20 bytes**, and asking again with the same label replaces that rule. **`duration`** is `24h`, `7d` or `30d`. - **The session signer is the app's passkey.** Its private key stays in the authenticator; `localStorage` holds the public key, credential id and session metadata. Each call asks the device to sign, and Nido's relayer submits it and pays the fee. Keep `PORT` fixed and use `localhost`, not an IP address, for local passkeys. Keep `credential_id` out of grant URLs. - **Check the cap before prompting.** Use `CapReachedError` and `capReachedUntil` to explain a spent cap and disable the action until it frees up. Renewing the same rules preserves the spending record. - **A cap limits a key, not the account's owner**, and **expiry stops a key, it doesn't delay a withdrawal**. For allowances, custody or time locks, put the money and the rule in your contract. - **Build contracts through Scaffold** (`npm run deploy:testnet`). A plain `stellar contract build` bakes the local network's XLM contract into the wasm, which fails on testnet with `Error(Context, InvalidAction)`. - **Call `submitCall` before any other `await`** in a click handler, so Nido's popup keeps the user's gesture. ## Commands and their side effects | Command | Deploys | Spends or writes keys | | --- | --- | --- | | `npm run tools:scaffold` | No | No | | `npm run doctor` (`-- --json` for a machine-readable report) | No | No, reads only | | `npm run clients:testnet` | No | Creates the deployer key and has Friendbot fund it, on first run | | `npm run deploy:testnet` | Yes | The deployer pays the fees | | `npm run dev` | No | Creates the deployer on first run | | `npm run test-browser` | No | Saves throwaway passkeys in `target/` | Keys and contract aliases live in the project's `.stellar-config/`, not the global `~/.config/stellar`, so several apps on one machine don't share identities. ## Check work against testnet, not mocks `npm run test:e2e` runs the real app with Nido's pages and the RPC mocked. It proves the app's side of each exchange, not that the chain accepts it. For the real flow without a person, `npm run test-browser` starts a throwaway Chrome whose tabs and popups all have a virtual passkey, and writes the connection settings for a browser driver to `target/test-browser.env`. Create the account at [test.nido.fyi](https://test.nido.fyi) in that browser. Some things to expect while driving it: - The wallet picker's buttons have no accessible names. Find the Nido entry by its text. - The app re-renders while a session loads. If your driver uses element references, take a fresh snapshot right before each click. - Nido's popup closes itself after an approval. That is the end of the flow, not an error. A run is done when you can show: 1. the account's C-address, the contract ID and the network; 2. the transaction hashes of real calls, with balances before and after; 3. the account's `installed_rules` showing the grants; 4. a refusal, and whether it came from simulation (free, nothing sent) or from a submitted transaction. ```sh npm run stellar -- contract invoke --id --network testnet --send=no -- installed_rules ``` ## When Nido's relayer refuses Account creation, grants and session calls go through Nido's relayer, out of one daily budget shared by everyone on testnet. Nido's signing page shows the same "couldn't confirm" message for a 429 `FEE_LIMIT_EXCEEDED` (nothing sent), a 503 `POOL_CAPACITY` (nothing sent) and a 504 (may have landed). Don't loop on retries: read `installed_rules`, then use the gate's **Check again** or **Ask Nido again**. The full table is in [Troubleshooting](/docs/troubleshooting/#nido-says-it-couldnt-confirm-what-happened). ## Not available yet Don't design around these; they don't exist yet: - revoking a session (grants end at their expiry); - Nido's grant page answering `?delegation=error&code=…` or `?delegation=signed&payload=…` (it sends only `ok` and `cancelled`); - a published Nido SDK for the session flow (it lives in the template's `app-lib/session.ts`); - a mainnet walkthrough in these guides.