Add get-balance html example

This commit is contained in:
Michael Vines 2018-08-23 19:46:27 -07:00
parent 3fb92bd062
commit 45360abc87
2 changed files with 41 additions and 1 deletions

View File

@ -9,7 +9,7 @@
<script src="../lib/index.iife.js"></script>
<!--
<script src="https://github.com/solana-labs/solana-web3.js/releases/download/v0.0.3/solanaWeb3.min.js"></script>
<script src="https://github.com/solana-labs/solana-web3.js/releases/download/v0.0.4/solanaWeb3.min.js"></script>
-->
<script>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Create a new account</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.0.4/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;
url = 'http://localhost:8899';
//url = 'http://master.testnet.solana.com:8899';
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>