LOADING...
You define your business logic in the program module. You accomplish this by creating functions that can be called by clients or other programs. For example in the code below 'hello_world' function simply logs "Hello world, from solana smart contract" message.
#[program]
pub mod hello_world {
use super::*;
pub fn hello_world(_ctx: Context<Initialize>) -> Result<()> {
msg!("Hello world, from solana smart contract");
Ok(())
}
}
The other example is like that:
#[program]
mod hello_anchor {
use super::*;
pub fn set_data(ctx: Context<SetData>, data: u64) -> Result<()> {
if ctx.accounts.token_account.amount > 0 {
ctx.accounts.my_account.data = data;
}
Ok(())
}
}
Now we have a program module as you can see in the right side. We created a program module named ahoy_there
And please create a function named `ahoy_there` which takes `ctx: Context<Initialize>` as a parameter. Waiit! What is ctx, Context and Initialize???
ahoy_there(ctx: Context<Initialize>)
No worry! We will cover them in next chapters! Just pass it :) Also, if you stuck somewhere do not hesitate to click show answer button.