Skip to content

Instantly share code, notes, and snippets.

@christroutner
Last active February 19, 2022 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christroutner/6cb9d1b615f3f9363af79723157bc434 to your computer and use it in GitHub Desktop.
Save christroutner/6cb9d1b615f3f9363af79723157bc434 to your computer and use it in GitHub Desktop.
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">
<head>
<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" />
</head>
<body>
<h1>Check BCH address balance</h1>
<p>
This page checks the balance of a BCH address.
</p>
<p>
The address bitcoincash:qppngav5s88devt4ypv3vhgj643q06tctcx8fnzewp has a
balance of this many sats:
</p>
<p id="bchStatus"></p>
<p></p>
</body>
<script src="https://unpkg.com/minimal-slp-wallet"></script>
<script>
document.addEventListener("DOMContentLoaded", async () => {
try {
console.log("hello world");
const wallet = new SlpWallet(undefined, {
noUpdate: true,
interface: "consumer-api"
});
const bchAddr =
"bitcoincash:qppngav5s88devt4ypv3vhgj643q06tctcx8fnzewp";
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);
}
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment