Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
add the tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
urani-engineering-helper committed Mar 27, 2024
1 parent 997b5b7 commit c4bf00c
Showing 1 changed file with 54 additions and 32 deletions.
86 changes: 54 additions & 32 deletions demos/01_hello_world/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
# 🛹 Demo 1: Hello World

--

### A "Hello World" Program

<br>

* In a separate terminal window, start your local cluster:


* Solana Rust programs follow the typical Rust project layout:

```
/inc/
/src/
/Cargo.toml
```shell
solana-test-validator
```

<br>

* Initialize a new Rust library via Cargo:

```
```shell
cargo init hello_world --lib
cd hello_world
cargo add solana-program
```

* This creates a very basic Solana Rust program following this layout:

```shell
-- src/
|__ lib.rs
-- Cargo.toml
```

* You should modify `Cargo.toml` to the following:

```
[package]
name = "hello_world"
version = "0.1.0"
[lib]
name = "hello_world"
crate-type = ["cdylib", "lib"]
[dependencies]
// add the right version
solana-program = "=1.1x.x"
```


<br>

* The Rust code for Solana lives inside `src/lib.rs`. There, you import your Rust crates and define your logic.
* We will write this program inside `src/lib.rs`.

* At the top of `lib.rs`, we import the `solana-program` crate and bring needed items into the local namespace:
* At the top, we import the `solana-program` crate and bring needed items into the local namespace:

```rust
use solana_program::{
Expand All @@ -44,19 +62,18 @@ use solana_program::{
<br>

* Every Solana program must define an `entrypoint` that tells the runtime where to start executing the code on-chain.

* The entry point should provide a public function named `process_instruction`:
- The entry point should provide a public function named `process_instruction`:

```rust
entrypoint!(process_instruction);

pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8]
pub fn process_instruction(
_program_id: &Pubkey,
_accounts: &[AccountInfo],
_instruction_data: &[u8]
) -> ProgramResult {

msg!("Solana Summer 2.0!");
msg!("Only possible on Solana");

Ok(())
}
Expand All @@ -65,38 +82,43 @@ entrypoint!(process_instruction);

<br>

* Every on-chain program should return the `Ok` result enum with value `()`.
- This tells the Solana runtime that the program executed successfully.
* Note that every on-chain program should return the `Ok` result enum with value `()`.
- This tells the Solana runtime that the program executed successfully.

<br>


#### Build your program

#### Build and Deploy your Program

<br>

* Let's build this hello world program, by running the following command from the root of the project:

```
cargo build-bpf
cargo build-sbf
```

<br>
* This command will create the compiled program's `.so` file inside a folder called `./target/deploy`:

```
find . -name '*.so'
```

#### Deploy your program:
* Now, let's deploy it:

<br>

```
solana program deploy ./target/deploy/hello_world.so
solana program deploy ./target/deploy/hello_world.so
```

<br>

* When this program finishes being deployed, the program's public address (`program id`) is displayed.

* To execute an on-chain program, you must send a transaction with a listing of instructions.
- Each `instruction` must include all the keys involved in the operation and the program ID we want to execute.
* You can check your Solana wallet's balance to see how much it costs to deploy this simple program.



<br>

---

0 comments on commit c4bf00c

Please sign in to comment.