Construction of rust for Solan RBPF (spare proof of function)
In this article, we will go to the process of building and laying rust, which can be pushed into the Solana (RBPF) reserve function to create a decentralized application.
Start
To start with, install the necessary addiction to salt and mine. Start the following command in the terminal:
`Bash
load new solana_hello -lib
This will create a new library of projects entitled “Solana_hello”. Then you can build it and start with:
`Bash
Location construction
Running loads
Hello World construction
The “Hello.RS” file defines our program as a simple function that prints “greetings, world!” To Solane blockchain. Let’s add a few use and applications for fun.
`Rust
Use anchor_lang :: Prelude ::*;
Declare_id! - Retailing ");
#[program]
Pub Mod Greetings {
Use great ::*;
pub fn hello () result <(), anchorerorror> {{
Let _ = ask! (Get_state_Query :: Condition as a result
All right(())
Iche
Iche
In this code we added a simple “hell” function, which downloads information about the current account using the “Get_state_Query” function. We also restore the result of this function to indicate whether the operation is successful.
twisting in brine
We will use Cli Sidre to organize our program in Solan. Start the following command:
`Bash
Construction of the anchor node -oT -UTPUTPUTPUT Path/to/Die
This will create a implementation package for ‘Path/to/Implementation’. Then we can transfer this package to the Solan junction using the “Anchor” command.
Adding an entry for RBPF
To use our program in RBPF Solana, we must add an input parameter. In this case, we will define a new type of entrance entitled “Hello_input”.
Add the following code to the “hello.RS” file:
`Rust
Use anchor_lang :: Prelude ::*;
Declare_id! - Retailing ");
#[program]
Pub Mod Hello {
Use great ::*;
Pub FN Hello (Input: hello_input :: Hellinput) -> result <(), anchorerorror> {
Let _ = ask! (Get_state_Query :: Condition as a result
All right(())
Iche
Iche
The type “hello_inputis one inlet parameter. In this case, we expect the "Hellinput
structure with one field called”.
Creating a RBPF Treaty
To create a RBPF agreement that uses our program as a connection function, we will define a new contract using the “Makro Treaty” Anchor.
`Rust
Use anchor_lang :: Prelude ::*;
Declare_id! - Retailing ");
#[program]
Pub Mod Greetings {
Use great ::*;
Pub FN Hello (hello_input :: Hellinput) -> result <(), anchorerorror> {
Let _ = ask! (Get_state_Query :: Condition as a result
All right(())
Iche
Iche
myrbpfContact contract {
Use the contract :: Prelude ::*;
Use Hello ::*;
Async fn main () -> result <()> {
Let account_id = Get_account (). Wait?;
Let input = hello_input :: helloinput {
Name: B "world" .to_vec (),
};
Let the result = myrbpfContract :: Invoke (entrance and []);
All right(())
Iche
Iche
In this code we have defined a new contract called “MyrBPFCONCANTACTI”. The “main” function creates an account and initiates an input parameter using our “hello_input” type.
construction and running
To build and start the RBPF contract, start the following commands:
`Bash
Location construction
Construction of the anchor node -oT -uTPUTPUTPUT Path/to/Die
This will create a new implementation package for the ‘path/to/implementation’. Then you can transfer this package to the Solan junction using the “Anchor” command.
Leave a Reply