Skip to content

Instantly share code, notes, and snippets.

@gentlyawesome
Created December 24, 2023 03:56
Show Gist options
  • Save gentlyawesome/0358efbc4498fc6145b1960bf5228224 to your computer and use it in GitHub Desktop.
Save gentlyawesome/0358efbc4498fc6145b1960bf5228224 to your computer and use it in GitHub Desktop.
use anchor_lang::prelude::*;
declare_id!("5gaQPYyZV2EzyMEG6z2a1B5ZpdXxGmru7eEV5pNZJeNv");
#[program]
pub mod mycalculator {
use anchor_lang::solana_program::entrypoint::ProgramResult;
use super::*;
pub fn create(ctx: Context<Create>, init_message: String) -> ProgramResult {
let calculator = &mut ctx.accounts.calculator;
calculator.greeting = init_message;
Ok(())
}
}
#[derive(Accounts)]
pub struct Create<'info> {
#[account(init, payer=user, space=264)]
pub calculator: Account<'info, Calculator>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct Calculator {
pub greeting: String,
pub results: i64,
pub remainder: i64,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment