Created
June 16, 2022 17:12
-
-
Save shawntabrizi/41df454c06fa291f4e807d748e0e944b to your computer and use it in GitHub Desktop.
the most simple polkadot js api example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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