Skip to content

Instantly share code, notes, and snippets.

@deanmlittle
Created November 30, 2023 15:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deanmlittle/966aed9b92d68fd794a2ad8cc9f6617f to your computer and use it in GitHub Desktop.
Save deanmlittle/966aed9b92d68fd794a2ad8cc9f6617f to your computer and use it in GitHub Desktop.
Anchor setup with airdrop and log/confirm functions
const program = anchor.workspace.AnchorVault as Program<AnchorVault>;
const connection = anchor.getProvider().connection;
const signer = Keypair.generate();
const vault = PublicKey.findProgramAddressSync([Buffer.from("vault"), signer.publicKey.toBuffer()], program.programId)[0];
const confirm = async (signature: string): Promise<string> => {
const block = await connection.getLatestBlockhash();
await connection.confirmTransaction({
signature,
...block
})
return signature
}
const log = async(signature: string): Promise<string> => {
console.log(`Your transaction signature: https://explorer.solana.com/transaction/${signature}?cluster=custom&customUrl=${connection.rpcEndpoint}`);
return signature;
}
it("Airdrop", async () => {
await connection.requestAirdrop(signer.publicKey, LAMPORTS_PER_SOL * 10)
.then(confirm)
.then(log)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment