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") + + }); +});