39 lines
1.1 KiB
HTML
39 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Get account balance</title>
|
|
</head>
|
|
<body>
|
|
<b>Account</b>
|
|
<div id="accountPublicKey">?</div>
|
|
has a balance of
|
|
<div id="accountBalance">?</div>
|
|
|
|
<script src="../lib/index.iife.js"></script>
|
|
<!--
|
|
<script src="https://github.com/solana-labs/solana-web3.js/releases/download/v0.11.10/solanaWeb3.min.js"></script>
|
|
-->
|
|
|
|
<script>
|
|
// Create a new account
|
|
const account = new solanaWeb3.Account();
|
|
|
|
// Display the account's public key
|
|
const accountPublicKey = document.getElementById('accountPublicKey');
|
|
accountPublicKey.innerHTML = account.publicKey;
|
|
|
|
// Fetch account balance
|
|
let url = 'http://localhost:8899';
|
|
//url = 'https://api.testnet.solana.com';
|
|
const connection = new solanaWeb3.Connection(url);
|
|
|
|
connection.getBalance(account.publicKey)
|
|
.then((balance) => {
|
|
const accountBalance = document.getElementById('accountBalance');
|
|
accountBalance.innerHTML = balance;
|
|
console.log(`${account.publicKey} has a balance of ${balance}`);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|