Skip to content

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.

License

Notifications You must be signed in to change notification settings

virjilakrum/Turbin3_solana_enrollment_typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Turbin3_prerequisites_risein

Solana Devnet Project (Turbin3)

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.

Table of Contents

  1. Transaction Links
  2. Project Setup
  3. Scripts and Commands
  4. File Descriptions

Transaction Links

Description Transaction Link
Airdrop Transaction View Transaction
Transfer Transaction View Transaction
Enroll Transaction View Transaction
1 2 3 4 5 6 7

Project Setup

  1. Ensure you have Node.js and Yarn installed.

  2. Create a new project directory and initialize it:

    mkdir airdrop && cd airdrop
    yarn init -y
  3. Install necessary packages:

    yarn add @types/node typescript @solana/web3.js bs58
    yarn add -D ts-node
  4. Generate TypeScript configuration:

    yarn tsc --init --rootDir ./ --outDir ./dist --esModuleInterop --lib ES2019 --module commonjs --resolveJsonModule true --noImplicitAny true

Scripts and Commands

Creating Keypair

Generate a new Solana wallet keypair:

yarn keygen

Claiming Airdrop

Request 2 SOL airdrop from Solana Devnet:

yarn airdrop

Making a Transfer

Transfer 0.1 SOL from your wallet to another wallet:

yarn transfer

Enrolling in Program

Submit your GitHub account to the Solana program:

yarn enroll

File Descriptions

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.

keygen.ts

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}]`);

airdrop.ts

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}`);
  }
})();

transfer.ts

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}`);
  }
})();

enroll.ts

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}`);
  }
})();

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published