Rust SDK
Rust SDK reference documentation.
JavaScript SDK
JavaScript SDK reference documentation.
Smart contracts on NEAR
This is how a smart contract written in Rust and JavaScript using the NEAR SDK looks like:- JavaScript
- Rust
Choose an SDK to start building contracts.
@NearBindgen({})
class HelloNear {
greeting: string = 'Hello';
@view({}) // This method is read-only and can be called for free
get_greeting(): string {
return this.greeting;
}
@call({}) // This method changes the state, for which it costs gas
set_greeting({ greeting }: { greeting: string }): void {
near.log(`Saving greeting ${greeting}`);
this.greeting = greeting;
}
}
#[near(contract_state)]
pub struct Contract {
greeting: String,
}
impl Default for Contract {
fn default() -> Self {
Self { greeting: "Hello".to_string(), }
}
}
#[near]
impl Contract {
pub fn get_greeting(&self) -> String {
self.greeting.clone()
}
pub fn set_greeting(&mut self, greeting: String) {
self.greeting = greeting;
}
}
Was this page helpful?