Created
November 30, 2023 15:33
-
-
Save deanmlittle/966aed9b92d68fd794a2ad8cc9f6617f to your computer and use it in GitHub Desktop.
Anchor setup with airdrop and log/confirm functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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