Skip to content

Wallet in 20 minutes

Upcoming · Demo mode is the next wallet SDK release. The devnet path below works today and takes longer than 20 minutes the first time.

When demo mode ships, this is the whole quickstart:

import { SwapClient, DemoWallet } from '@fondaco/wallet-sdk';

const client = new SwapClient({ mode: 'demo' });          // no relay URL, no app id, no key
const wallet = new DemoWallet({ USDM: 1_000_000_000n });  // or a real connector in demo mode
const r = await client.swap(wallet, {
  give: 'USDM',
  want: 'NIGHT',
  amount: 25_000_000n,
  receiver: wallet.receiver(),
});
console.log(r.status.state); // finalized

What it will do, from the plan in docs/devex.md §2:

  • The demo relay answers with one firm quote, signed by a demo solver key, and one indicative quote from a ladder, attests them with a fixed demo key, and the client runs its real checks against them.
  • The fill walks reserved → made → submitted → finalized, the state names the production relay uses, on a compressed clock; realtime: true paces it like Preprod so a UI's progress steps can be tested.
  • Every response carries a DEMO marker, also in r.status.
  • scenario reproduces the production relay's error shapes: no_quote, paused, declined, fade, reserve_race, ws_refused, privacy_unavailable.

What is mocked lists what demo mode will fake and what it will not.

What works today: the SDK against the local devnet

Section titled “What works today: the SDK against the local devnet”

The same SDK, against a real relay with real solvers, on the repository's devnet (a single-node chain running the ledger WASM). It needs the whole stack, so budget an afternoon for the first run.

Prerequisites. Node ≥ 22.12, Elixir ≥ 1.18 with OTP ≥ 28, Rust 1.95, nats-server and Postgres, and a checkout of the repository.

1. Build and start the stack. From the repository root:

npm ci && npm run build
DATABASE_URL=ecto://user:pass@localhost/si_relay_dev scripts/stack.sh up

That starts NATS, the devnet on :7300, the relay on http://localhost:4000, our solvers and the matcher, and three devnet wallets behind the dApp connector API (:7500 holds only USDM, so its fees are sponsored; :7501 holds NIGHT and DUST; :7502 is for resting offers). Solvers start in dry run: start the stack with AUTO_ADMIT=true, or admit them after a few requests with node scripts/seed-programme.mjs --admit.

2. Swap in the browser. Open http://localhost:4000. The page loads the devnet wallet the way a browser extension would inject itself, so it is the integration a real wallet gets. http://localhost:4000/regression runs the integration end to end: a network check, a buy and a sell through to settlement, and a limit offer posted and cancelled, with pass or fail and timings for each step.

3. Swap from your own code. SwapClient is the whole client. The relay registers a partner app on the devnet with the key devnet-partner-key:

import { SwapClient } from '@si/wallet-sdk'; // @fondaco/wallet-sdk once published

const client = new SwapClient({
  relayUrl: 'http://localhost:4000',
  appId: 'partner-wallet',
  apiKey: 'devnet-partner-key',
});

// `wallet` is a connected dApp connector API (connector 4.x): an extension in a browser,
// or the devnet wallet's RPC in Node.
const r = await client.swap(wallet, {
  give: 'USDM',
  want: 'NIGHT',
  amount: 25_000_000n,                      // 25 USDM, six decimals
  receiver: { unshielded: myNightAddressHex },
  onProgress: (p) => console.log(p.stage),  // quoted, accepted, …, status
});
console.log(r.status.state, r.status.txId); // finalized | failed | expired

The repository's trade script does exactly this from Node, against a demo wallet's RPC, including the connector shim and a leg check from @si/ledger-kit. It was written for and run on Preprod (docs/PREPROD.md); it takes any relay and wallet URL, but we have not yet run it against the devnet stack as a quickstart, so treat this command as the starting point rather than a tested recipe:

RELAY_URL=http://localhost:4000 WALLET_URL=http://127.0.0.1:7500 node scripts/preprod-wallet-trade.mjs USDM 25 NIGHT --sponsor

It prints one JSON line per step: the wallet and its balances, the quotes, the accept, and the fill's final state with the time of each stage.

What the client checks before your wallet signs

Section titled “What the client checks before your wallet signs”

quote() refuses a response unless the relay's attestation is signed with the key the client holds (from its options or the relay's /network, never from the response), is for the network, app, pair and amount it asked for, and commits to exactly the quotes returned; each firm quote must carry its solver's valid signature. execute() checks the accept against the request and the quote before the wallet does anything. For a solver's leg (solver_offer) it needs a leg check from you (checkLeg); without one, the client asks for user_offer quotes only. The full list is in the wallet SDK README and §8 and §10 of the MIP draft.

Error When
RelayError A non-2xx answer from the relay (with its status), or a response that fails the client's checks (502)
SwapWalletError The wallet failed or refused; failure says which class
NoQuoteError No solver quoted

On a USDM → NIGHT buy, the USDM the user pays is hidden; the NIGHT they receive arrives at a public address, with its amount. The swap page says this before the wallet signs; your app should too. The wording the public site uses is on what is private.

  • Preprod. The same code against the hosted Preprod relay: relayUrl: 'https://preprod-relay.fondaco.network', the public test app demo (its app id and its key), and tsSIT, Preprod's shielded test token, where the samples say USDM; see docs/PREPROD.md.
  • Limit offers. postLimitOffer, cancelLimitOffer and book in the wallet SDK reference.
  • Your own app id, app fee and revenue share. The integration guide.