Skip to content

Instantly share code, notes, and snippets.

Last active February 19, 2022 16:40
What would you like to do?
Example of using minimal-slp-wallet in a web page

The HTML file below shows how to import minimal-slp-wallet into a web page and query the balance of a BCH address from the blockchain. This is a simple example for interacting with the BCH blockchain with a web page.

A live demo of this app has been uploaded to Filecoin, and can be accessed here:

<!DOCTYPE html>
This HTML page checks the balance of a BCH address.
<html lang="en">
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Check BCH Balance</title>
<link rel="icon favicon" href="favicon.ico" />
<h1>Check BCH address balance</h1>
This page checks the balance of a BCH address.
The address bitcoincash:qppngav5s88devt4ypv3vhgj643q06tctcx8fnzewp has a
balance of this many sats:
<p id="bchStatus"></p>
<script src=""></script>
document.addEventListener("DOMContentLoaded", async () => {
try {
console.log("hello world");
const wallet = new SlpWallet(undefined, {
noUpdate: true,
interface: "consumer-api"
const bchAddr =
const balance = await wallet.getBalance(bchAddr);
console.log(`balance: `, balance);
// Update DOM.
const balanceText = document.getElementById("bchStatus");
balanceText.innerHTML = `${balance}`;
} catch (err) {
console.error("Error in web app: ", err);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment