Skip to content

Commit

Permalink
solana airdrop v1
Browse files Browse the repository at this point in the history
nodejs based solana v1
  • Loading branch information
kranthicodes committed Jan 16, 2022
1 parent d2db0d4 commit 9cf4013
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
49 changes: 49 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const {
Connection,
PublicKey,
clusterApiUrl,
Keypair,
LAMPORTS_PER_SOL,
Transaction,
Account,
} = require("@solana/web3.js");

const newPair = new Keypair();
const publicKey = new PublicKey(newPair._keypair.publicKey).toString();
const secretKey = newPair._keypair.secretKey;

const getWalletBalance = async () => {
try {
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const myWallet = await Keypair.fromSecretKey(secretKey);
const walletBalance = await connection.getBalance(
new PublicKey(myWallet.publicKey)
);
console.log(`=> For wallet address ${publicKey}`);
console.log(
` Wallet balance: ${parseInt(walletBalance) / LAMPORTS_PER_SOL}SOL`
);
} catch (err) {
console.log(err);
}
};
const airDropSol = async () => {
try {
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const walletKeyPair = await Keypair.fromSecretKey(secretKey);
console.log(`-- Airdropping 2 SOL --`);
const fromAirDropSignature = await connection.requestAirdrop(
new PublicKey(walletKeyPair.publicKey),
2 * LAMPORTS_PER_SOL
);
await connection.confirmTransaction(fromAirDropSignature);
} catch (err) {
console.log(err);
}
};
const driverFunction = async () => {
await getWalletBalance();
await airDropSol();
await getWalletBalance();
};
driverFunction();
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "sol-airdrop",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kranthicodes/sol-airdrop.git"
},
"keywords": [],
"author": "Sai Kranthi",
"license": "ISC",
"bugs": {
"url": "https://github.com/kranthicodes/sol-airdrop/issues"
},
"homepage": "https://github.com/kranthicodes/sol-airdrop#readme",
"dependencies": {
"@solana/web3.js": "^1.31.0"
}
}
Loading

0 comments on commit 9cf4013

Please sign in to comment.