From 26c4bc6be046b15f68eac09b928b01120feb9ab5 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Fri, 21 Jan 2022 10:00:04 +0530 Subject: [PATCH 1/2] Changes to few console.log messages. --- src/client/hello_world.ts | 20 ++++++++++---------- src/client/main.ts | 8 +++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/client/hello_world.ts b/src/client/hello_world.ts index 3e33f9e4..2bfb0fe0 100644 --- a/src/client/hello_world.ts +++ b/src/client/hello_world.ts @@ -90,7 +90,7 @@ export async function establishConnection(): Promise { const rpcUrl = await getRpcUrl(); connection = new Connection(rpcUrl, 'confirmed'); const version = await connection.getVersion(); - console.log('Connection to cluster established:', rpcUrl, version); + console.log('\nConnection to Solana cluster established:', rpcUrl, version); } /** @@ -122,11 +122,11 @@ export async function establishPayer(): Promise { } console.log( - 'Using account', - payer.publicKey.toBase58(), + '\nUsing Solana blockchain account: ', + '[' + payer.publicKey.toBase58() + ']', 'containing', lamports / LAMPORTS_PER_SOL, - 'SOL to pay for fees', + 'SOL to pay for fees.', ); } @@ -158,7 +158,7 @@ export async function checkProgram(): Promise { } else if (!programInfo.executable) { throw new Error(`Program is not executable`); } - console.log(`Using program ${programId.toBase58()}`); + console.log(`\nUsing Solana blockchain program ID: [${programId.toBase58()}].`); // Derive the address (public key) of a greeting account from the program so that it's easy to find later. const GREETING_SEED = 'hello'; @@ -172,7 +172,7 @@ export async function checkProgram(): Promise { const greetedAccount = await connection.getAccountInfo(greetedPubkey); if (greetedAccount === null) { console.log( - 'Creating account', + '\nCreating account', greetedPubkey.toBase58(), 'to say hello to', ); @@ -199,7 +199,7 @@ export async function checkProgram(): Promise { * Say hello */ export async function sayHello(): Promise { - console.log('Saying hello to', greetedPubkey.toBase58()); + console.log('\nNow saying hello to Solana blockchain account ID: [' + greetedPubkey.toBase58() + '].'); const instruction = new TransactionInstruction({ keys: [{pubkey: greetedPubkey, isSigner: false, isWritable: true}], programId, @@ -225,10 +225,10 @@ export async function reportGreetings(): Promise { GreetingAccount, accountInfo.data, ); - console.log( - greetedPubkey.toBase58(), + console.log('\nSolana blockchain account ID: ' + + '[' + greetedPubkey.toBase58() + ']', 'has been greeted', greeting.counter, - 'time(s)', + 'time(s) so far!', ); } diff --git a/src/client/main.ts b/src/client/main.ts index 621c533d..95ed4ef5 100644 --- a/src/client/main.ts +++ b/src/client/main.ts @@ -11,8 +11,9 @@ import { } from './hello_world'; async function main() { - console.log("Let's say hello to a Solana account..."); - + console.log("****************************************************************************") + console.log("Let's say hello to a Solana blockchain account!"); + console.log("****************************************************************************") // Establish connection to the cluster await establishConnection(); @@ -28,7 +29,8 @@ async function main() { // Find out how many times that account has been greeted await reportGreetings(); - console.log('Success'); + console.log('\nSuccess!!'); + console.log("*****************************************************************************"); } main().then( From 83f6a3467384c177bb368488823f7dfbfeb84240 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Fri, 21 Jan 2022 11:47:24 +0530 Subject: [PATCH 2/2] Airdrop 1 SOL to Payer account --- src/client/hello_world.ts | 13 +++++++++++++ src/program-c/src/helloworld/helloworld.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/hello_world.ts b/src/client/hello_world.ts index 2bfb0fe0..51838444 100644 --- a/src/client/hello_world.ts +++ b/src/client/hello_world.ts @@ -111,6 +111,18 @@ export async function establishPayer(): Promise { } let lamports = await connection.getBalance(payer.publicKey); + console.log('\nPayer Account ID: [' + payer.publicKey + '].'); + console.log('\nPayer Account Balance (Before Airdrop): ' + lamports/LAMPORTS_PER_SOL + ' SOL.'); + + // Request an Airdrop (although not needed) 1 SOL (LAMPORTS_PER_SOL) + const myAirDrop = await connection.requestAirdrop( + payer.publicKey, + LAMPORTS_PER_SOL + ); + await connection.confirmTransaction(myAirDrop); + lamports = await connection.getBalance(payer.publicKey); + console.log('\nPayer Account Balance (After Airdrop): ' + lamports/LAMPORTS_PER_SOL + ' SOL.'); + if (lamports < fees) { // If current balance is not enough to pay for fees, request an airdrop const sig = await connection.requestAirdrop( @@ -217,6 +229,7 @@ export async function sayHello(): Promise { */ export async function reportGreetings(): Promise { const accountInfo = await connection.getAccountInfo(greetedPubkey); + if (accountInfo === null) { throw 'Error: cannot find the greeted account'; } diff --git a/src/program-c/src/helloworld/helloworld.c b/src/program-c/src/helloworld/helloworld.c index 8de25495..46422c2a 100644 --- a/src/program-c/src/helloworld/helloworld.c +++ b/src/program-c/src/helloworld/helloworld.c @@ -25,7 +25,7 @@ uint64_t helloworld(SolParameters *params) { return ERROR_INVALID_ACCOUNT_DATA; } - // Increment and store the number of times the account has been greeted + // Increment and store the number of times the account has been greeted uint32_t *num_greets = (uint32_t *)greeted_account->data; *num_greets += 1;