chore: add get_account_info example (#18713)

add getaccountinfo example
This commit is contained in:
chaseeb 2021-07-16 19:47:17 -04:00 committed by GitHub
parent 181f21529d
commit 919c3ae6ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -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);
})();