Rust Developer Guide
Last updated
// 1. Set the target to wasm32 and enable no_std for compatibility.
// no_std is required since WebAssembly's minimal runtime lacks support for Rust’s standard library.
#![cfg_attr(target_arch = "wasm32", no_std)]
// 2. Import FluentBase SDK
extern crate fluentbase_sdk;
use fluentbase_sdk::{basic_entrypoint, derive::Contract, SharedAPI};
// 3. Define Contract Struct with SDK: Acts as the core of the contract’s logic.
#[derive(Contract)]
struct GREETING<SDK> {
sdk: SDK,
}
impl<SDK: SharedAPI> GREETING<SDK> {
// 4. Deployment Logic: Placeholder for setup during deployment.
fn deploy(&mut self) {
// Add any custom deployment logic here
}
// 5. Core Contract Logic: writes "Hello, World" message to output.
fn main(&mut self) {
self.sdk.write("Hello, World".as_bytes());
}
}
// 6. Set Entry Point: Connects GREETING struct to the WASM runtime.
basic_entrypoint!(GREETING);gblend build rust -rgblend deploy --private-key <PRIVATE_KEY> --dev lib.wasm --gas-limit 300000000