In this example, we will use requestAirdrop, but you can use sendTransaction or any other method that returns a Promise<TransactionSignature>.
Establish a connection to your RPC.
While this goal could be accomplished by any node connection on the Solana network, here at QuickNode, we make it quick and easy to set up a Solana node.
You can register for a free trial, as well as see pricing
here.
Make sure to launch your node under the Solana Devnet and copy the HTTP link:
Navigate back to the index.js file and establish a connection to Solana Devnet with the following constants:
build a sample transaction
const solanaDevnet = 'https://example.solana-devnet.quiknode.pro/000000/';
const solanaConnection = new Connection(solanaDevnet);
const solanaDevnet = 'https://example.solana-devnet.quiknode.pro/000000/';
const solanaConnection = new Connection(solanaDevnet);
const solanaDevnet = 'https://example.solana-devnet.quiknode.pro/000000/';
const solanaConnection = new Connection(solanaDevnet);
Define a public key to airdrop tokens to:
build a sample transaction
const toDropPublicKey = new PublicKey('YOUR_PUBLIC_KEY');
const toDropPublicKey = new PublicKey('YOUR_PUBLIC_KEY');
const toDropPublicKey = new PublicKey('YOUR_PUBLIC_KEY');
Establish timeout and iteration variables. For this exercise, we will check if a transaction's status every statusCheckInterval (ms) for a period of timeout (ms) (As of this writing, the transaction's blockhash will expire after 150 blocks or ~1 minute and 19 seconds.). Additionally, we will define a sleep function to control our loop timing and declare a boolean, isBlockhashValid, which we will use later.
build a sample transaction
const statusCheckInterval = 300;
const timeout = 90000;
let isBlockhashValid = true;
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
const statusCheckInterval = 300;
const timeout = 90000;
let isBlockhashValid = true;
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
const statusCheckInterval = 300;
const timeout = 90000;
let isBlockhashValid = true;
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
Create a Transaction and define your initialBlock by calling await solanaConnection.getSignatureStatus(txId)).context.slot (Note: even dropped transactions should include this context):
build a sample transaction
(async()=>{
const airdropSignature = solanaConnection.requestAirdrop(
toDropPublicKey,
LAMPORTS_PER_SOL, //Airdrop 1 SOL
); const txId = await airdropSignature;
const inititalBlock = (await solanaConnection.getSignatureStatus(txId)).context.slot
})()
(async()=>{
const airdropSignature = solanaConnection.requestAirdrop(
toDropPublicKey,
LAMPORTS_PER_SOL, //Airdrop 1 SOL
); const txId = await airdropSignature;
const inititalBlock = (await solanaConnection.getSignatureStatus(txId)).context.slot
})()
(async()=>{
const airdropSignature = solanaConnection.requestAirdrop(
toDropPublicKey,
LAMPORTS_PER_SOL, //Airdrop 1 SOL
); const txId = await airdropSignature;
const inititalBlock = (await solanaConnection.getSignatureStatus(txId)).context.slot
})()