Connect to Fiber with a WASM Node
Run a Fiber node in a React application, connect it to Fiber Testnet over WSS, and monitor its state without a backend service.
Run the Fiber node in the browser
The Fiber WASM node runs inside the React application rather than on a remote server. Web Workers execute the runtime, IndexedDB stores node data, and WSS connects the browser node to a public Fiber peer.
This quickstart runs the Fiber node entirely in the browser and does not require a backend. Applications that issue invoices, verify merchant payments, or manage server-side content can add a backend service as needed.
Install the browser SDK
Create a Next.js application and install the Fiber browser SDK. The SDK provides the Fiber WASM runtime and node lifecycle APIs required by the React application.
npm create next-app@latest fiber-hello
cd fiber-hello
npm install @fiber-pay/sdkConfigure COOP and COEP headers
The Fiber WASM runtime uses SharedArrayBuffer to exchange data between its workers. Browsers expose this API only on cross-origin-isolated pages, so configure COOP and COEP response headers for the /fiber route.
Start the node without connecting
Before creating the node, verify that crossOriginIsolated is enabled. Then create a credential and initialize a Fiber Testnet node with an empty bootnode list so it starts without connecting to a peer. Register the stateChange listener before calling node.start() to receive startup updates.
The generated credentials are intended for Testnet development only. Production applications must store private keys in encrypted storage and provide backup, account-switching, and recovery mechanisms.
Connect the node to a public peer
After the node starts locally, call connectToRouter(node) to connect it to Testnet. Because connectPeer accepts the transport address and public key as separate fields, the helper removes the /p2p/<peer-id> suffix and passes the remaining WSS address with routerPubkey.
Persist the node across React renders
Store the node instance in a ref so it remains available across renders without triggering rerenders. Store its status, public key, and peer count in React state so changes appear in the interface.
app/fiber/page.tsx · lines 7–11Start the WASM node
The start handler calls startFiber, stores the returned node, and retrieves its public key with getNodeInfo. The public key identifies the running browser node. No peer connection is established at this stage.
Connect the running node to Testnet
After startup, the connect handler passes the stored node to connectToRouter. It then calls listPeers and stores the returned peer count so the interface can confirm the connection.
Display node status and connection results
Bind the start and connect handlers to separate buttons. Display the node status, public key, and peer count so users can verify that the node started and connected successfully.
app/fiber/page.tsx · lines 27–39Run the Live Demo
Start the local WASM node, then connect it to a public peer.
Waiting for nodewasm_runtimecheckingnode_stateReady to start