Skip to content

Instantly share code, notes, and snippets.

@shawntabrizi
Last active September 11, 2024 20:57
Show Gist options
  • Save shawntabrizi/b342a29ee464c8d2c6bb1694af8d6019 to your computer and use it in GitHub Desktop.
Save shawntabrizi/b342a29ee464c8d2c6bb1694af8d6019 to your computer and use it in GitHub Desktop.
Play with Polkadot
<!DOCTYPE html>
<html lang="en">
<head>
<title>Play with Polkadot</title>
</head>
<body>
<h1>Play with Polkadot</h1>
<pre id="output">Loading page...</pre>
</body>
<!-- These are pre-packaged Polkadot JS bundles so you can access Polkadot from a simple html page. -->
<script src="//unpkg.com/@polkadot/util/bundle-polkadot-util.js"></script>
<script src="//unpkg.com/@polkadot/util-crypto/bundle-polkadot-util-crypto.js"></script>
<script src="//unpkg.com/@polkadot/types/bundle-polkadot-types.js"></script>
<script src="//unpkg.com/@polkadot/api/bundle-polkadot-api.js"></script>
<script src="//unpkg.com/@polkadot/keyring/bundle-polkadot-keyring.js"></script>
<script>
async function queryPolkadot() {
try {
const { ApiPromise, WsProvider } = polkadotApi;
const wsProvider = new WsProvider('wss://rpc.polkadot.io'); // Adjust which network you want to query. Try `wss://kusama-rpc.polkadot.io`.
document.getElementById('output').innerText = "Connecting to RPC endpoint..."
const api = await ApiPromise.create({ provider: wsProvider });
const address = "5DksjtJER6oLDWkWKCWcL3f1swPWeNNFsS9zHxa2rPa7LsH9";
const data = await api.query.system.account(address); // Change this query! Try `api.query.staking.ledger(address)`.
document.getElementById('output').innerText = JSON.stringify(data, null, 2);
} catch (error) {
document.getElementById('output').innerText = "Error. See console (F12)";
console.error("Error:", error);
}
}
queryPolkadot(); // We run the query as soon as the page loads.
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment