These lessons will show how easy it is to create smart contracts on the Vara platform using the Sails framework. It provides the initial steps and core concepts for a confident start on Vara.
Sails is a library for bringing your experience of writing applications utilizing Gear Protocol to the next level of simplicity and clarity.
It deals with things like:
This lesson covers creating a program that outputs “Hello, world!”
The architecture of Sails applications is based on several key concepts.
#[service]
attribute represents the service, which
implements an aspect of the application's business logic.#[program]
attribute represents the program. The
program's primary role is to host one or more services and expose them to external consumers.The program requires the service to function. Program implementation must follow Gear protocol architecture.
Code explanation:
In the code on the right, the sails_rs::prelude module provides necessary imports.
The #[service]
attribute defines the HelloWorld
struct. This service has a single-method greeting
that returns the
string "Hello, world!".
The #[program]
attribute defines the MyProgram
struct. This program includes a method hello_world
that creates a
new instance of the HelloWorld
struct. The program's public methods, taking &self
and no other arguments, serve
as exposed service constructors. These public methods are called each time an incoming request message needs to be sent
to a selected service.
#![no_std]
use sails_rs::prelude::*;
pub struct HelloWorld(());
#[service]
impl HelloWorld {
pub fn greeting(&mut self) -> &'static str {
"Hello, world!"
}
}
pub struct MyProgram;
#[program]
impl MyProgram {
pub fn new() -> Self {
Self
}
pub fn hello_world(&self) -> HelloWorld {
HelloWorld(())
}
}
These lessons will show how easy it is to create smart contracts on the Vara platform using the Sails framework. It provides the initial steps and core concepts for a confident start on Vara.
Sails is a library for bringing your experience of writing applications utilizing Gear Protocol to the next level of simplicity and clarity.
It deals with things like:
This lesson covers creating a program that outputs “Hello, world!”
The architecture of Sails applications is based on several key concepts.
#[service]
attribute represents the service, which
implements an aspect of the application's business logic.#[program]
attribute represents the program. The
program's primary role is to host one or more services and expose them to external consumers.The program requires the service to function. Program implementation must follow Gear protocol architecture.
Code explanation:
In the code on the right, the sails_rs::prelude module provides necessary imports.
The #[service]
attribute defines the HelloWorld
struct. This service has a single-method greeting
that returns the
string "Hello, world!".
The #[program]
attribute defines the MyProgram
struct. This program includes a method hello_world
that creates a
new instance of the HelloWorld
struct. The program's public methods, taking &self
and no other arguments, serve
as exposed service constructors. These public methods are called each time an incoming request message needs to be sent
to a selected service.
#![no_std]
use sails_rs::prelude::*;
pub struct HelloWorld(());
#[service]
impl HelloWorld {
pub fn greeting(&mut self) -> &'static str {
"Hello, world!"
}
}
pub struct MyProgram;
#[program]
impl MyProgram {
pub fn new() -> Self {
Self
}
pub fn hello_world(&self) -> HelloWorld {
HelloWorld(())
}
}