This project demonstrates creating a Solana wallet, performing airdrop and transfer transactions, and interacting with a Solana program. Below are the detailed steps and commands to execute each part of the project.
Description | Transaction Link |
---|---|
Airdrop Transaction | View Transaction |
Transfer Transaction | View Transaction |
Enroll Transaction | View Transaction |
-
Ensure you have Node.js and Yarn installed.
-
Create a new project directory and initialize it:
mkdir airdrop && cd airdrop yarn init -y
-
Install necessary packages:
yarn add @types/node typescript @solana/web3.js bs58 yarn add -D ts-node
-
Generate TypeScript configuration:
yarn tsc --init --rootDir ./ --outDir ./dist --esModuleInterop --lib ES2019 --module commonjs --resolveJsonModule true --noImplicitAny true
Generate a new Solana wallet keypair:
yarn keygen
Request 2 SOL airdrop from Solana Devnet:
yarn airdrop
Transfer 0.1 SOL from your wallet to another wallet:
yarn transfer
Submit your GitHub account to the Solana program:
yarn enroll
File Name | Description |
---|---|
keygen.ts | Script to generate a new Solana wallet keypair. |
airdrop.ts | Script to request SOL tokens from Solana Devnet to the generated wallet. |
transfer.ts | Script to transfer SOL from the generated wallet to another specified wallet. |
enroll.ts | Script to interact with the Solana program and submit your GitHub account. |
import { Keypair } from "@solana/web3.js";
// Generate a new keypair
let kp = Keypair.generate();
console.log(`You've generated a new Solana wallet: ${kp.publicKey.toBase58()}`);
console.log(`Solana Wallet Secret Key: ${kp.secretKey}]`);
import { Connection, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
import wallet from "./dev-wallet.json";
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
const connection = new Connection("https://api.devnet.solana.com");
(async () => {
try {
const txhash = await connection.requestAirdrop(keypair.publicKey, 2 * LAMPORTS_PER_SOL);
console.log(`Başarılı! İşlemi buradan kontrol edebilirsiniz:
https://explorer.solana.com/tx/${txhash}?cluster=devnet`);
} catch (e) {
console.error(`Hata oluştu: ${e}`);
}
})();
import { Transaction, SystemProgram, Connection, Keypair, LAMPORTS_PER_SOL, sendAndConfirmTransaction, PublicKey } from "@solana/web3.js";
import wallet from "./dev-wallet.json";
const from = Keypair.fromSecretKey(new Uint8Array(wallet));
const to = new PublicKey("Write here the public key of the second wallet you created");
const connection = new Connection("https://api.devnet.solana.com");
(async () => {
try {
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: from.publicKey,
toPubkey: to,
lamports: LAMPORTS_PER_SOL / 100,
})
);
transaction.recentBlockhash = (await connection.getLatestBlockhash('confirmed')).blockhash;
transaction.feePayer = from.publicKey;
const signature = await sendAndConfirmTransaction(
connection,
transaction,
[from]
);
console.log(`Başarılı! İşlemi buradan kontrol edebilirsiniz:
https://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch (e) {
console.error(`Hata oluştu: ${e}`);
}
})();
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { Program, Wallet, AnchorProvider } from "@coral-xyz/anchor";
import { IDL, WbaPrereq } from "./programs/wba_prereq";
import wallet from "./dev-wallet.json";
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
const connection = new Connection("https://api.devnet.solana.com");
const github = Buffer.from("your_github_account", "utf8");
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment: "confirmed" });
const program = new Program<WbaPrereq>(IDL, new PublicKey(IDL.address), provider);
const enrollment_seeds = [Buffer.from("prereq"), keypair.publicKey.toBuffer()];
const [enrollment_key, _bump] = PublicKey.findProgramAddressSync(enrollment_seeds, program.programId);
(async () => {
try {
const txhash = await program.methods
.complete(github)
.accounts({
signer: keypair.publicKey,
prereq: enrollment_key,
systemProgram: PublicKey.default,
})
.signers([keypair])
.rpc();
console.log(`Başarılı! İşlemi buradan kontrol edebilirsiniz:
https://explorer.solana.com/tx/${txhash}?cluster=devnet`);
} catch (e) {
console.error(`Hata oluştu: ${e}`);
}
})();