# Deploy your first smart contract

Yona is an SVM L2 and is fully compatible with Solana smart contracts and development tools. Let's write and deploy a Hello World smart contract from scratch.

## Setup your local environment

### Install Cargo and Rust

First, let's install Cargo (a package manager) and Rust compiler so that we can build and manage dependencies of our smart contracst

```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### Install Solana CLI

We will use `solana` command line (CLI) tool to generate key and deploy our smart contract. To install Solana CLI, run:

```sh
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
```

Depending on your operating system, the Solana CLI may automatically update `PATH` environment variable or may ask you to add to update the `PATH` manually.

```
Please update your PATH environment variable to include the Solana programs:
```

If you get the above message, simply copy and paste the command recommended by the Solana CLI installer to update your `PATH` environment variable.

Next restart your terminal to make sure your `solana` binaries are accessible in all the terminal sessions. To check this, ask Solana CLI to print its version:

```sh
solana --version
```

Now we need to set an RPC URL to point to Yona RPC:

```sh
solana config set --url https://devnet-rpc.yona.network/
```

or

```bash
solana config set --url https://testnet.yona.network/
```

## Create a new Yona smart contract project

### Yona smart contracts are Rust libraries [#](https://solana.com/developers/guides/getstarted/local-rust-hello-world#create-a-new-rust-library-with-cargo) <a href="#create-a-new-rust-library-with-cargo" id="create-a-new-rust-library-with-cargo"></a>

Yona contracts are written in Rust and are *libraries* that compile to `.so` format.

First, Initialize a new Rust library named `hello_world` via the Cargo command line:

```sh
cargo init hello_world --lib
cd hello_world
```

Add the `solana-program` crate to your new Rust library:

```sh
cargo add solana-program
```

{% hint style="info" %}
It is highly recommended to keep your `solana-program` and other Solana Rust dependencies in-line with your installed version of the Solana CLI. For example, if you are running Solana CLI 1.18.14, you can instead run:

```
cargo add solana-program@"=1.18.14"
```

{% endhint %}

Open your `Cargo.toml` file and add these required Rust library configuration settings, updating your project name as appropriate:

```toml
[lib]
name = "hello_world
"crate-type = ["cdylib", "lib"]
```

As a result, your `Cargo.toml` file should look like this:

```toml
[package]
name = "hello_world"
version = "0.1.0"
edition = "2024"

[lib]
name = "hello_world"
crate-type = ["cdylib", "lib"]


[dependencies]
solana-program = "1.18.14"
```

## Create your first Yona smart contract [#](https://solana.com/developers/guides/getstarted/local-rust-hello-world#create-your-first-solana-program) <a href="#create-your-first-solana-program" id="create-your-first-solana-program"></a>

Your Rust based Yona smart contract will live in your `src/lib.rs` file.  There you can import your Rust crates and define your logic. Open your `src/lib.rs` file in your favorite editor. We recommend VSCode with `rust-analyzer` extension.&#x20;

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

```rust
use solana_program::{
    account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey,
};
```

Every Yona smart contract must define an `entrypoint` that tells the Yona runtime where to start executing your onchain code. Your program's entrypoint should be a public function:

```rust
// declare and export the program's entrypoint
entrypoint!(process_instruction);

// program entrypoint's implementation
pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    // log a message to the blockchain
    msg!("Hello, world!");

    // gracefully exit the program
    Ok(())
}

```

Every smart contract should return the `Ok` [result enum](https://doc.rust-lang.org/std/result/) with a value of `()`. This tells the Yona runtime that your program executed successfully without errors.

The smart contract above will simply log "*Hello, world!*" to the blockchain cluster, then exit with `Ok(())`.

## Build your Yona smart contract [#](https://solana.com/developers/guides/getstarted/local-rust-hello-world#build-your-rust-program) <a href="#build-your-rust-program" id="build-your-rust-program"></a>

In a terminal, you can build your Yona smart contract  by running in the root of your project (i.e. the directory with your `Cargo.toml` file):

```
cargo build-bpf
```

## Deploy your Yona smart contract [#](https://solana.com/developers/guides/getstarted/local-rust-hello-world#deploy-your-solana-program)

First, we need to create and fund a Yona account. Run the following comand:

```sh
solana-keygen new --outfile deploy_keypair.json
```

When asked for the passphrase, leave it empty (press enter):

```
BIP39 Passphrase (empty for none): Wrote new keypair to deploy_keypair.json
```

As a result, `solana-keygen` will create a `deploy_keypair.json` and out the corresponding pubkey and seed phrase:

```
=====================================================================================
pubkey: AWVhMZ7TFbeYo2B5vifRmacGjVV1dqVEwTtQeEgWh6LQ
=====================================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX 
=====================================================================================
```

To fund the account linked to this pubkey, join Yona Discord at [https://discord.gg/yonanetwork](https://t.co/B3Yfii4WqH), go to #devnet-faucet channel, and send 'faucet' command to this channel:

```
faucet AWVhMZ7TFbeYo2B5vifRmacGjVV1dqVEwTtQeEgWh6LQ
```

Using the Solana CLI, you can deploy your Yona smart contract:

```sh
solana program deploy ./target/deploy/hello_world.so -k deploy_keypair.json
```

Once your Yona smart contract has been deployed, it will output your smart contract public address (aka its "program id").

```
outputProgram Id: EFH95fWg49vkFNbAdw9vy75tM7sWZ2hQbTTUmuACGip3
```

## **Congratulations!** [**#**](https://solana.com/developers/guides/getstarted/local-rust-hello-world#congratulations!)

You have successfully setup, built, and deployed a Yona smart contract using the Rust language.

\ <br>
