-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
486 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains 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
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(); |
This file contains 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
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" | ||
} | ||
} |
Oops, something went wrong.