The server wallet runs on Node.js using a private key and @bsv/wallet-toolbox. It's used for automated operations, payment processing, and funding flows where no user interaction is needed.
Creating a Server Wallet
Copy import { ServerWallet } from ' @bsv/simple/server '
const wallet = await ServerWallet . create ( {
privateKey : process . env . SERVER_PRIVATE_KEY ! ,
network : ' main ' ,
storageUrl : ' https://storage.babbage.systems '
} )
console . log ( ' Identity Key: ' , wallet . getIdentityKey ()) What Happens During Creation
A PrivateKey and KeyDeriver are created from the hex key
A WalletStorageManager, WalletSigner, and Services instance are configured
A StorageClient connects to the storage URL and becomes available
The ToolboxWallet is instantiated and all module methods are mixed in
The composed ServerWallet is returned
The server wallet uses a request/response pattern to receive funds from a browser wallet:
Step 1: Server Creates a Payment Request
This generates a random BRC-29 derivation suffix so the server can later prove ownership of the payment.
Step 2: Browser Wallet Funds the Server
Step 3: Client Sends Transaction to Server
Step 4: Server Internalizes the Payment
This uses the wallet payment protocol to internalize the output with proper derivation info, so the server wallet can spend it later.
Private Key Persistence
Key persistence is handled automatically by handler factories. If you need lower-level access, use generatePrivateKey() instead of importing @bsv/sdk:
For Next.js API routes, use the handler factory which manages key persistence automatically:
Key persistence order (automatic):
process.env.SERVER_PRIVATE_KEY — Environment variable (production)
.server-wallet.json file — Persisted from previous run (development)
Auto-generated via generatePrivateKey() — Fresh key (first run)
Important: Add .server-wallet.json to your .gitignore. Never commit private keys.
The server wallet has all the same methods as the browser wallet:
createToken(), listTokenDetails(), sendToken(), redeemToken()
inscribeText(), inscribeJSON(), inscribeFileHash(), inscribeImageHash()
certifyForMessageBox(), sendMessageBoxPayment(), listIncomingPayments(), acceptIncomingPayment()
acquireCertificateFrom(), listCertificatesFrom(), relinquishCert()
getDID(), resolveDID(), registerDID()
acquireCredential(), listCredentials(), createPresentation()
advertiseSHIP(), advertiseSLAP(), broadcastAction(), withRetry()
Next.js API Route Example
See the Next.js Integration Guide for a complete API route implementation with caching and key persistence.