Build an App Examples

Examples

These examples are intentionally small. They show how to shape the app flow around user-controlled approvals instead of hiding the wallet behind your backend.

Donate Button

Connect the wallet, prefill a recipient address, and let the user send a small BTC amount with a chosen fee rate.

Authenticated Dashboard

Use signMessage() to prove wallet ownership before unlocking higher-trust actions in your app.

Example 1: Donation Widget

JavaScript
async function donate() {
  const photon = window.photon;
  if (!photon) throw new Error("Install PhotonBolt Wallet first");

  await photon.connect();

  const txid = await photon.sendTransaction({
    to: "tb1qmerchantaddress0000000000000000000000000",
    amountBtc: "0.00005",
    feeRate: 2
  });

  console.log("Donation sent", txid);
}

Example 2: Wallet Ownership Challenge

JavaScript
async function signLoginChallenge(challenge) {
  const photon = window.photon;
  if (!photon) throw new Error("PhotonBolt Wallet missing");

  await photon.connect();
  const [address] = await photon.getAccounts();
  const signature = await photon.signMessage(challenge);

  return { address, signature };
}

Example 3: Show Account, Network, and Balance

JavaScript
async function loadWalletSummary() {
  if (!window.photon) return null;

  await window.photon.connect();

  const [address] = await window.photon.getAccounts();
  const network = await window.photon.getNetwork();
  const balance = await window.photon.getBalance();

  return { address, network, balance };
}

Example 4: Prepare Then Send

If your product needs a second confirmation step in the app UI, use signTransaction() for preview-oriented flows and sendTransaction() for final send.

JavaScript
async function prepareThenSend(to, amountBtc) {
  const signedHex = await window.photon.signTransaction({
    to,
    amountBtc,
    feeRate: 2
  });

  console.log("Preview signed hex", signedHex);

  const txid = await window.photon.sendTransaction({
    to,
    amountBtc,
    feeRate: 2
  });

  return txid;
}