From 6139228c62baac768bf97c4d12ddf3be947d10aa Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 13 Nov 2024 16:34:48 -0400 Subject: [PATCH] First Commit --- client/client.ts | 16 ++++++++++++++++ src/lib.rs | 15 +++++++++++++++ tests/anchor.test.ts | 25 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 client/client.ts create mode 100644 src/lib.rs create mode 100644 tests/anchor.test.ts diff --git a/client/client.ts b/client/client.ts new file mode 100644 index 0000000..cddad87 --- /dev/null +++ b/client/client.ts @@ -0,0 +1,16 @@ +const helloWorld = async () => { + const transaction = await pg.program.methods.helloWorld().transaction(); + + const transactionID = await web3.sendAndConfirmTransaction( + pg.connection, + transaction, + [pg.wallet.keypair] + ); + + console.log( + "Transaction Complete: ", + `https://explorer.solana.com/tx/${transactionID}?cluster=devnet` + ); +}; + +helloWorld(); diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d11ee13 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,15 @@ +use anchor_lang::prelude::*; + +declare_id!("5UQcesyNGAypwzk8zudC2FL2fGrDYi4DyvEwGmmi7n45"); + +#[program] +mod hello_anchor { + use super::*; + pub fn hello_world(_ctx: Context) -> Result<()> { + msg!("Hello World from Solana Blockchain"); + Ok(()) + } +} + +#[derive(Accounts)] +pub struct HelloWorld {} diff --git a/tests/anchor.test.ts b/tests/anchor.test.ts new file mode 100644 index 0000000..63696c8 --- /dev/null +++ b/tests/anchor.test.ts @@ -0,0 +1,25 @@ +// No imports needed: web3, anchor, pg and more are globally available + +describe("HelloWorld", () => { + it("HelloWorld", async () => { + // Generate keypair for the new account + const newAccountKp = new web3.Keypair(); + + const txHash = await pg.program.methods.helloWorld() + .accounts({ + newAccount: newAccountKp.publicKey, + signer: pg.wallet.publicKey, + systemProgram: web3.SystemProgram.programId, + }) + .signers([newAccountKp]) + .rpc(); + + console.log(`Use 'solana confirm -v ${txHash} to see the logs`); + + // Confirm transaction + await pg.connection.confirmTransaction(txHash); + + console.log("Hello World did") + + }); +});