Open a Fiber Channel and Send a Payment
Fund your browser node, open a real Testnet payment channel, and send CKB over Fiber—all from React and WASM.
A channel turns one on-chain setup into fast payments
Opening a channel commits Testnet CKB on-chain. Once the channel reaches ChannelReady, payments update the channel off-chain instead of creating a new CKB transaction each time.
Starting and connecting do not move funds. Opening the channel and sending the payment happen only after you click their separate buttons.
Send Testnet CKB to the generated address
Start the same browser identity used in the connection tutorial. The SDK derives its CKB funding address from default_funding_lock_script. Use the faucet, then refresh until the on-chain balance appears.
Express CKB as hexadecimal shannons
Fiber RPC amounts use hexadecimal shannons. Parse the decimal string with BigInt so eight-decimal CKB values stay exact and do not pass through floating-point numbers.
499 CKB = 49,900,000,000 shannons0xb9e0ab300Commit funding to the public Testnet peer
Call openChannel() only after the browser node is running, the public peer is connected, and the funding address has enough CKB. The example makes the channel public so it can participate in routing.
The selected public Testnet node auto-accepts CKB channels at or above 499 CKB. Each side also reserves 99 CKB for channel contracts and shutdown.
Do not enable payments when negotiation merely starts
openChannel() returns a temporary channel ID before the funding transaction is ready. Poll listChannels()and unlock the payment UI only when a channel state contains ready.
Use keysend for the smallest working example
Pass the recipient pubkey, an amount, and keysend: trueto sendPayment(). Keysend avoids invoice generation, which keeps this first payment flow entirely in the browser.
Not for this direct keysend demo. A merchant app usually adds a backend to create invoices, match payments to orders, and grant access after server-side verification.
Wait for a terminal payment status
A submitted payment can still be in flight. If the first response is not Success or Failed, callwaitForPayment() and update the React UI with its terminal status.
Start, then connect
Starting restores local identity and channel data. Connecting is a separate user action, just like the first tutorial. The code panel highlights both handlers as one explicit preparation step.
app/pay/page.tsx · lines 23–37Open, then pay
The channel button requires a connected peer. The payment button remains disabled until a stored or new channel is ready, so every state-changing action stays separate and explicit.
app/pay/page.tsx · lines 39–49Keep the browser node; harden everything around it
Before handling real funds, encrypt keys, add backup and recovery, validate channel liquidity, surface fees and timeouts, and decide whether invoices need server-side order verification.