Skip to content

Instantly share code, notes, and snippets.

@shawntabrizi
Created June 16, 2022 17:12
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 shawntabrizi/41df454c06fa291f4e807d748e0e944b to your computer and use it in GitHub Desktop.
Save shawntabrizi/41df454c06fa291f4e807d748e0e944b to your computer and use it in GitHub Desktop.
the most simple polkadot js api example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<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 type="text/javascript">
const { WsProvider, ApiPromise } = polkadotApi;
async function getAccountInfo() {
const wsProvider = new WsProvider('wss://rpc.polkadot.io');
const api = await ApiPromise.create({ provider: wsProvider });
const address = document.getElementById("address").value
const accountInfo = await api.query.system.account(address);
document.getElementById("output").innerHTML = accountInfo;
}
</script>
</head>
<body>
<h1>Polkadot Account Fetcher</h1>
<p>Enter your Polkadot Address:</p>
<input type="text" size="50" id="address" />
<button type="button" onClick="getAccountInfo();">Get Account Info</button>
<br />
<br />
<div id="output"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment