Solana Development Tutorial: Program 101

Image for post
Image for post

Before we start

Connect to Devnet

ubuntu@VM-0-12-ubuntu:~$ solana config set --url
Config File: /home/ubuntu/.config/solana/cli/config.yml
WebSocket URL: wss:// (computed)

Prepare your account

solana-keygen new
ubuntu@VM-0-12-ubuntu:~$ solana-keygen pubkey /home/ubuntu/.config/solana/id.json
ubuntu@VM-0-12-ubuntu:~$ solana airdrop 10 7FqW6xXE4sMmZSeVxFsoTr83He4MhhePvA1vRAv9zgQf
Requesting airdrop of 10 SOL from
10 SOL
ubuntu@VM-0-12-ubuntu:~$ solana balance 7FqW6xXE4sMmZSeVxFsoTr83He4MhhePvA1vRAv9zgQf
10 SOL
solana-keygen new -o solana_memo_program.json

Compile the program

git clone
cargo build-bpf
= note: /usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
sudo apt install gcc-multilib
To deploy this program:
$ solana deploy /home/ubuntu/solana/solana-program-library/target/deploy/
solana-keygen pubkey ~/solana_memo_program.json
solana deploy /home/ubuntu/solana/solana-program-library/target/deploy/ ~/solana_memo_program.json
Image for post
Image for post

Test your program

yarn init
yarn add @solana/web3.js
var solana_web3 = require('@solana/web3.js');function testMemo(connection, account){
const instruction = new solana_web3.TransactionInstruction({
keys: [],
programId:new solana_web3.PublicKey('D8Cnv1UcThay2WijWP4SQ8G683UuVsKPaZEU7TNVKW1j'),
data: Buffer.from('cztest'),
console.log("account:", account.publicKey.toBase58())
new solana_web3.Transaction().add(instruction),
skipPreflight: true,
commitment: "singleGossip",
}function main() {
connection = new solana_web3.Connection("", 'singleGossip');
const account = new solana_web3.Account()
const lamports = 10*1000000000
connection.requestAirdrop(account.publicKey, lamports).then(()=>{
console.log("airdrop done")
testMemo(connection, account)
Image for post
Image for post
>>> import binascii
>>> binascii.a2b_hex('637a74657374')

Write your own program

cargo new onchain_program
arrayref = "0.3.6"
num-derive = "0.3"
num-traits = "0.2"
num_enum = "0.5.1"
solana-program = "1.4.8"
thiserror = "1.0"[dev-dependencies]
solana-sdk = "1.4.8"[lib]
crate-type = ["cdylib", "lib"][]
targets = ["x86_64-unknown-linux-gnu"]
#![deny(missing_docs)]//! A simple program that return success.#[cfg(not(feature = "no-entrypoint"))]
mod entrypoint;// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;
//! Program entrypointuse solana_program::{
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, program_error::ProgramError,
use std::str::from_utf8;entrypoint!(process_instruction);
fn process_instruction(
_program_id: &Pubkey,
_accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
cargo build-bpf...To deploy this program:
$ solana deploy /home/ubuntu/solana/memo_test/onchain_program/target/deploy/



solong wallet

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store