I have a simple solana greeting-counter program, I have it deployed locally. When I am calling from my typescript code I am able to do pretty much all the transactions and verify them. Except the last one, where I am seeing the block explorer is showing the transaction went through it's a success, however when I try to read the data I am seeing the state has not been updated. I am using anchor 0.30.0
Here is the Solana App Code:
use anchor_lang::prelude::*;
declare_id!("8VEC1cycS5ry9aM5CBRWtxfVQBfNtWANTXXrXXmk2TXw");
#[program]
pub mod hello_please {
use super::*;
pub fn create_greeting(ctx: Context<CreateGreeting>) -> Result<()> {
let greeting_account = &mut ctx.accounts.greeting_account;
greeting_account.counter = 0;
Ok(())
}
pub fn increment_greeting(ctx: Context<IncrementGreeting>) -> Result<()> {
let greeting_account = &mut ctx.accounts.greeting_account;
greeting_account.counter += 1;
Ok(())
}
}
#[derive(Accounts)]
pub struct CreateGreeting<'info> {
#[account(init, payer = user, space = 8 + 8)]
pub greeting_account: Account<'info, GreetingAccount>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct IncrementGreeting<'info> {
#[account(mut)]
pub greeting_account: Account<'info, GreetingAccount>,
}
#[account]
pub struct GreetingAccount {
pub counter: u64,
}
Here is the Typescript code :
interface GreetingAccount {
counter: anchor.BN
}
async function main() {
// Everything has been initialized
const txSignature = await program.methods
.incrementGreeting()
.accounts({
greetingAccount: greetingAccount.publicKey,
})
.signers([providerAccount])
.rpc();
const latestBlockHash = await connection.getLatestBlockhash();
await connection.confirmTransaction({
blockhash: latestBlockHash.blockhash,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
signature: txSignature,
}, 'finalized');
const accountInfo = await connection.getAccountInfo(greetingAccount.publicKey);
if (accountInfo === null) {
throw new Error("Error: Account not found");
}
const GreetingAccountSchema = borsh.struct<GreetingAccount>([borsh.u64("counter"),]);
const {counter} = GreetingAccountSchema.decode(accountInfo?.data, "processed");
console.log("decoded counter: "+counter.toNumber()+"\n");
}();
My console.log is showing 0
but the explorer shows it as 1
when I use msg! macro