1 1 Hello World

- 1 min

lib.rs

//1. 引入相关定义
use solana_program::{
    account_info::AccountInfo,
    entrypoint,
    entrypoint::ProgramResult,
    publicKey::PubKey,
    msg
}

// 2. 定义入口函数
entrypoint!(process_instruction); 

pub fn process_instruction(
    _program_id: &Pubkey,
    _account: &[AccountInfo],
    _instruction_data: &[u8],
) -> ProgramResult {
    msg!("hello world");
    Ok(())
}

client.ts


console.log(`address ${pg.wallet.publicKey.toString()}`);
const balance = await pg.connection.getBalance(pg.wallet.publicKey);
console.log(`my balance: ${balance / web3.LAMPORTS_PER_SOL} sol.`)

const transaction = new web3.Transaction()

transaction.add(
    web3.TransactionInstruction({
        keys:[],
        programId: new web3.PublicKey(pg.PROGRAM_ID)
    })
)
const hash = await web3.sendAndConfirmTransaction(
    pg.connection,
    transaction,
    [pg.wallet.keypair]
)

console.log(`tranactions hash ${hash}`)