> For the complete documentation index, see [llms.txt](https://docs.put.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.put.com/developers/get-started/rust-program.md).

# Rust program

## Rust Program Quickstart

Rust is the most common programming language to write PUT programs with.&#x20;

This quickstart guide will demonstrate how to quickly setup, build, and deploy your first Rust based PUT program to the blockchain.

NOTE: This guide uses the PUT CLI and assumes you have setup your local development environment. Checkout our local development quickstart guide here to quickly get setup.

## What you will learn\#

* How to install the Rust language locally
* How to initialize a new PUT Rust program
* How to code a basic PUT program in Rust
* How to build and deploy your Rust program

## Install Rust and Cargo

To be able to compile Rust based PUT programs, install the Rust language and Cargo (the Rust package manager) using Rustup:

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

## Run your localhost validator

The PUT CLI comes with the test validator built in.&#x20;

This command line tool will allow you to run a full blockchain cluster on your machine.

```
put-test-validator
```

PRO TIP:&#x20;

Run the PUT test validator in a new/separate terminal window that will remain open.&#x20;

This command line program must remain running for your localhost validator to remain online and ready for action.

Configure your PUT CLI to use your localhost validator for all your future terminal commands and PUT program deployment:

```
put config set --url localhost
```

## Create a new Rust library with Cargo

PUT programs written in Rust are libraries which are compiled to BPF bytecode and saved in the .so format.

Initialize a new Rust library named hello\_world via the Cargo command line:

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

Add the put-program crate to your new Rust library:

```
cargo add put-program
```

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

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

## Create your first PUT program

The code for your Rust based PUT program will live in your src/lib.rs file.&#x20;

Inside src/lib.rs you will be able to import your Rust crates and define your logic.&#x20;

Open your src/lib.rs file in your favorite editor.

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

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

Every PUT program must define an entrypoint that tells the PUT runtime where to start executing your on chain code.&#x20;

Your program's entrypoint should provide a public function named process\_instruction:

```
// 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 on chain program should return the Ok result enum with a value of ().&#x20;

This tells the PUT runtime that your program executed successfully without errors.

This program above will simply log a message of "Hello, world!" to the blockchain cluster, then gracefully exit with Ok(()).

Build your Rust program#

Inside a terminal window, you can build your PUT Rust program by running in the root of your project (i.e. the directory with your Cargo.toml file):

```
cargo build-bpf
```

NOTE: After each time you build your PUT program, the above command will output the build path of your compiled program's .so file and the default keyfile that will be used for the program's address.

## Deploy your PUT program

Using the PUT CLI, you can deploy your program to your currently selected cluster:

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

Once your PUT program has been deployed (and the transaction finalized), the above command will output your program's public address (aka its "program id").

```
# example output
Program Id: EFH95fWg49vkFNbAdw9vy75tM7sWZ2hQbTTUmuACGip3
```

Congratulations!#

You have successfully setup, built, and deployed a PUT program using the Rust language.

PS: Check your PUT wallet's balance again after you deployed. See how much PUT it cost to deploy your simple program?

## Next steps

See the links below to learn more about writing Rust basedPUT programs:

```
Overview of writing PUT programs
Learn more about developing PUT programs with Rust
Debugging on chain programs
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.put.com/developers/get-started/rust-program.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
