From 919c3ae6ec61415e9a47af4993958d4c3cbf8890 Mon Sep 17 00:00:00 2001 From: chaseeb Date: Fri, 16 Jul 2021 19:47:17 -0400 Subject: [PATCH] chore: add get_account_info example (#18713) add getaccountinfo example --- web3.js/examples/get_account_info.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 web3.js/examples/get_account_info.js diff --git a/web3.js/examples/get_account_info.js b/web3.js/examples/get_account_info.js new file mode 100644 index 0000000000..07bb3122d2 --- /dev/null +++ b/web3.js/examples/get_account_info.js @@ -0,0 +1,25 @@ +import * as web3 from '@solana/web3.js'; + +(async () => { + // Connect to cluster + var connection = new web3.Connection( + web3.clusterApiUrl('devnet'), + 'confirmed', + ); + + // Generate a new wallet keypair and airdrop SOL + var wallet = web3.Keypair.generate(); + var airdropSignature = await connection.requestAirdrop( + wallet.publicKey, + web3.LAMPORTS_PER_SOL, + ); + + //wait for airdrop confirmation + await connection.confirmTransaction(airdropSignature); + + // get account info + // account data is bytecode that needs to be deserialized + // serialization and deserialization is program specic + let account = await connection.getAccountInfo(wallet.publicKey); + console.log(account); +})();