7 / 9
Your own app
Add it to an existing app
This is a different project: a recipe box you built before you heard of create-bsv-app. You ran add mode on it:
Terminal
npx create-bsv-app@latest add --capabilities wallet-connect,wallet-login --yesAdd mode wrote helper files into client/src/bsv/ and server/src/bsv/ (open them: they're the real ones). It never edits your main.tsx, App.tsx or server entry. It puts the snippets to paste in AGENTS.md, under Wiring (manual). That part is yours.
Your task#
- In
client/src/main.tsx, importWalletProvidersfrom./bsv/WalletProvidersand wrap<App />in it. - In
client/src/App.tsx, add the<ConnectWallet />button and a Log in button that callslogin()fromuseWalletLogin(). Connect in the preview. - Logging in fails: your server has no identity and no login route.
AGENTS.md's snippet assumes a generated server with aserverWalletalready in it, and yours has none. Inserver/src/index.ts, add a server wallet,GET /api/identityandPOST /api/login:
ts
const key = process.env.SERVER_PRIVATE_KEY
if (key == null && process.env.NODE_ENV === 'production') throw new Error('SERVER_PRIVATE_KEY is required in production')
const serverWallet = new ProtoWallet(key != null ? PrivateKey.fromString(key) : PrivateKey.fromRandom())
app.get('/api/identity', async (_req, res) => {
const { publicKey } = await serverWallet.getPublicKey({ identityKey: true })
res.json({ identityKey: publicKey })
})
app.post('/api/login', loginRoute(serverWallet))(Import PrivateKey and ProtoWallet from @bsv/sdk, and loginRoute from ./bsv/loginRoute.js.) Then log in.
Your task
- Wrap the app in WalletProviders and connect
- Give the server an identity and a login route, then log in