| 
									
										
										
										
											2018-08-23 19:46:27 -07:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  | <head> | 
					
						
							| 
									
										
										
										
											2018-11-07 08:52:01 -08:00
										 |  |  |   <title>Get account balance</title> | 
					
						
							| 
									
										
										
										
											2018-08-23 19:46:27 -07:00
										 |  |  | </head> | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  |   <b>Account</b> | 
					
						
							|  |  |  |   <div id="accountPublicKey">?</div> | 
					
						
							|  |  |  |   has a balance of | 
					
						
							|  |  |  |   <div id="accountBalance">?</div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <script src="../lib/index.iife.js"></script> | 
					
						
							|  |  |  |   <!--
 | 
					
						
							| 
									
										
										
										
											2018-11-07 08:52:01 -08:00
										 |  |  |     <script src="https://github.com/solana-labs/solana-web3.js/releases/download/v0.11.10/solanaWeb3.min.js"></script> | 
					
						
							| 
									
										
										
										
											2018-08-23 19:46:27 -07:00
										 |  |  |   --> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <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 | 
					
						
							| 
									
										
										
										
											2018-11-07 08:52:01 -08:00
										 |  |  |     let url = 'http://localhost:8899'; | 
					
						
							| 
									
										
										
										
											2018-08-23 19:46:27 -07:00
										 |  |  |     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> |