bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 6쪽
"
;
contract
BlendedCounter
{
IPowerCalculator
public
immutable powerCalculator
;
constructor
(
address
_powerCalculator
)
{
powerCalculator
=
IPowerCalculator
(
_powerCalculator
)
;
}
function
useWasmContract
(
)
public
{
uint256
result
=
powerCalculator
.
power
(
2
,
8
)
;
}
}
To learn more about how the calls dispatched to Wasm contracts works, check out the
Router macro
in Fluentbase SDK
💡
Router Macro
The router macro provides a robust method dispatch system for Fluentbase smart contracts. It automatically transforms function calls with Solidity-compatible selectors into appropriate Rust function calls, handling parameter decoding and result encoding.
Deployment
When your contracts successfully compile, you can deploy the contract to Fluent Network. You'll find the commands to deploy again very familiar to those of regular forge, with a few small edits.
Deploy WASM Contract
gblend create PowerCalculator.wasm
\
--rpc-url https://rpc.testnet.fluent.xyz
\
--private-key
$PRIVATE_KEY
\
--broadcast
\
--verify
\
--wasm
\
--verifier
blockscout
\
--verifier-url https://testnet.fluentscan.xyz/api/
Deploy Solidity Contract
gblend create src/BlendedCounter.sol:BlendedCounter
\
--rpc-url https://rpc.testnet.fluent.xyz
\
--private-key
$PRIVATE_KEY
\
--broadcast
\
--constructor-args
<
powerCalculatorAddress
>
Deploy Using Script
gblend script script/BlendedCounter.s.sol:Deploy
\
--rpc-url https://rpc.testnet.fluent.xyz
\
--private-key
$PRIVATE_KEY
\
--broadcast
Verification
Fluent Network uses Blockscout as
its block explorer
and functionality has been built in to not only verify Solidity contracts, but also Fluentbase Wasm contracts.
Verify WASM Contract
gblend verify-contract
<
address
>
PowerCalculator.wasm
\
--wasm
\
--verifier
blockscout
\
--verifier-url https://testnet.fluentscan.xyz/api/
Pay attention to add the
--wasm
flag when verifying WASM contracts!
Verify Solidity Contract
gblend verify-contract
<
address
>
BlendedCounter
\
--verifier
blockscout
\
--verifier-url https://testnet.fluentscan.xyz/api/
\
--constructor-args
<
args
>
Testing WASM Contracts
In Forge Tests
contract
BlendedCounterTest
is
Test
{
address
public
powerCalculator
;
function
setUp
(
)
public
{
// Deploy WASM contract in tests
powerCalculator
=
vm
.
deployCode
(
"out/PowerCalculator.wasm/foundry.json"
)
;
}
function
testWasmIntegration
(
)
public
{
IPowerCalculator calc
=
IPowerCalculator
(
powerCalculator
)
;
assertEq
(
calc
.
power
(
2
,
3
)
,
8
)
;
}
}
Best Practices for Building
🏆
Become a gblend chef
Always use Docker
for WASM builds to ensure reproducibility
Follow naming conventions
for WASM contracts (PascalCase.wasm)
Test locally
before deployment
Verify contracts
immediately after deployment
Advanced Usage
Custom Templates
As the Fluentbase ecosystem grows, we're building a collection of templates and examples in our
examples repository
. These working implementations showcase various use cases and patterns for blended applications, from simple starters to complex DeFi protocols.
Initialising with a Custom Template
# Create a new project with a custom template
gblend init
-t
fluentlabs-xyz/power-calculator power-calculator
Adding a Custom Template to an Existing Project
# If you want to add a specific WASM contract into existing gblend project
gblend init
-t
fluentlabs-xyz/power-calculator src/power-calculator
The above will create the new Contract package in the
/src
directory. If you want a custom path that is different, you can use:
# Add contract to <custom-path>
gblend init
-t
fluentlabs-xyz/power-calculator
<
custom-path
>
/power-calculator
Multi-Contract Deployment
// script/Deploy.s.sol
contract
Deploy
is
Script
{
function
run
(
)
external
{
vm
.
startBroadcast
(
)
;
// Deploy WASM contract
bytes
memory
wasmBytecode
=
vm
.
getCode
(
"out/PowerCalculator.wasm/foundry.json"
)
;
address
powerCalculator
;
assembly
{
powerCalculator
:=
create
(
0
,
add
(
wasmBytecode
,
0x20
)
,
mload
(
wasmBytecode
)
)
}
require
(
powerCalculator
!=
address
(
0
)
,
"WASM deployment failed"
)
;
// Deploy Solidity contract with WASM dependency
BlendedCounter counter
=
new
BlendedCounter
(
powerCalculator
)
;
vm
.
stopBroadcast
(
)
;
}
}
Ready to Build?
Now that you've mastered the basics of gblend, it's time to put your skills to work!
🎯 Explore Real Examples
: Dive into our
example projects
to see gblend in action. These working implementations showcase best practices and provide ready-to-use templates for your own blended applications.
🚀 Start Building
: Ready to create something amazing? Follow our comprehensive
developer guides
to build your first blended application from scratch.
Whether you're looking for inspiration or ready to code, we've got you covered. Choose your path and start building the future of blended applications!
Using
gblend
Getting Started
1. Create a New Project
2. Project Structure
3. Build Contracts
4. Run Tests
Configuration
foundry.toml
Rust Configuration (Cargo.toml)
Working with WASM Contracts
Building WASM Contracts
Using WASM in Solidity
Deployment
Deploy WASM Contract
Deploy Solidity Contract
Deploy Using Script
Verification
Verify WASM Contract
Verify Solidity Contract
Testing WASM Contracts
In Forge Tests
Best Practices for Building
Advanced Usage
Custom Templates
Multi-Contract Deployment
Ready to Build?
## /gblend/troubleshooting
On this page
Troubleshooting FAQs
When developing with
gblend
, always keep the following in mind:
🏆
Best Practice
Always use Docker
for WASM builds to ensure reproducibility
Follow naming conventions
for WASM contracts (PascalCase.wasm)
Test locally
before deployment
Verify contracts
immediately after deployment
If something isn't working properly, review the troubleshooting FAQs below to find a quick solution.
FAQ
Build fails with Docker error
🚩
Problem
:
gblend build
fails with Docker-related errors.
✅
Solution
: Ensure Docker is installed and running:
# Check Docker status
docker
info
# Start Docker daemon (Linux)
sudo
systemctl start
docker
# On macOS, start Docker Desktop application
Error: "command not found: gblend"
🚩
Problem
:
gblend
command is not recognized after installation.
✅
Solution
:
Restart your terminal or run
source ~/.bashrc (or ~/.zshrc)
Check installation path:
which gblend
Verify PATH includes
gblend
location
WASM contract verification fails
🚩
Problem
: Verification fails with "contract not found" error.
✅
Solution
: Ensure correct naming convention:
Use PascalCase with
.wasm
extension
Example:
my-contract
→
MyContract.wasm
Cannot import WASM interface in Solidity
🚩
Problem
: Import statement fails for WASM interface.
✅
Solution
:
Build the project first:
gblend build
Check that interface exists:
ls out/PowerCalculator.wasm/interface.sol
Use correct import path relative to your Solidity file
First build takes too long
🚩
Problem
: Initial build is slow.
✅
Solution
: This is expected behavior. The first build downloads the Docker container image for reproducible WASM compilation. Subsequent builds will be faster.
WASM contract deployment fails
🚩
Problem
: Contract creation returns address(0).
✅
Solution
:
Check WASM bytecode was generated:
ls out/PowerCalculator.wasm/
Ensure sufficient gas for deployment
Verify network RPC URL is correct
Still encountering issues?
If none of the above solves the issue you're facing, refer
Discord
for discussing the issue and getting support from fellow community devs and DevRels, in the
#devs-forum
channel.
Troubleshooting FAQs
FAQ
Build fails with Docker error
Error: "command not found: gblend"
WASM contract verification fails
Cannot import WASM interface in Solidity
First build takes too long
WASM contract deployment fails
Still encountering issues?
## /fluentbase-sdk/build-w-fluentbase-sdk
On this page
Build with the Fluentbase SDK
⚠️
Warning
The Fluentbase SDK is in experimental development and is still a work in progress.
All bindings, methods, and naming conventions within the codebase are not standardized and may change significantly.
Additionally, the codebase has not been audited or fully tested, which could lead to potential vulnerabilities or
crashes.
Architecture Overview
Fluentbase operates using Fluent's
rWasm VM
(reduced WebAssembly), which employs a 100% compatible WebAssembly
binary representation optimized for zero-knowledge operations. The instruction set is reduced, and sections are embedded
inside the binary to simplify the proving process.
The SDK provides a unified development environment that bridges multiple execution environments, enabling developers to
write smart contracts that can interact seamlessly across different virtual machines.
🔍
Supported Languages
The Fluentbase SDK currently supports writing
smart contracts
in:
Rust
- Full featured support with derive macros and storage
optimization
Solidity
- EVM-compatible contracts with seamless
interoperability
Future iterations will introduce more language support.
Supported Types
Fluentbase supports automatic conversion between Solidity and Rust types. For a complete mapping reference, see
the
Type Conversion Guide
.
Modules
The Fluentbase framework consists of several core modules that work together to provide a complete development
framework:
1.
crates
Contains all
Fluentbase modules
that form the core SDK
functionality:
build
Helper functions and CLI for compiling Fluentbase smart contracts. Supports deterministic Docker builds, custom Rust toolchains, and multiple output formats (WAT, rWASM, ABI, Solidity interface files, and metadata). Powers the build scripts for precompiled contracts.
codec
A lightweight, no-std compatible codec library optimized for random reads. While similar to Solidity ABI encoding, it introduces optimizations for efficient data access and nested structures. Supports two encoding modes: CompactABI (little-endian, 4-byte alignment) and SolidityABI (big-endian, 32-byte alignment for Ethereum compatibility).
codec-derive
Procedural macros for deriving the Codec trait from the fluentbase-codec crate. Generates efficient encoding and decoding implementations that integrate with both CompactABI and SolidityABI modes.
contracts
System precompiled contracts bundled with Fluentbase runtimes. Includes EVM and SVM compatibility layers, cryptographic primitives (SHA256, Blake2, etc.), and the reference ERC20 implementation. Compiles each contract to rWASM and embeds binaries for genesis file inclusion.
erc20
Reference implementation of the ERC20 token standard built using the Fluentbase SDK. Demonstrates recommended project layout and SDK entrypoint macros usage. Implements standard transfer, approve, and transfer_from methods with Fluentbase key-value storage.
evm
Execution engine implementing Ethereum Virtual Machine semantics on top of Fluentbase types. Provides a minimal EVM for compatibility tests and running Solidity contracts compiled to rWASM. Includes opcode interpreter, gas accounting, memory model, and stack implementation matching Ethereum specification.
genesis
Utilities for creating and manipulating genesis files that bundle Fluentbase precompiled contracts. Produces JSON genesis files compatible with Reth or other clients for starting local development networks with correct rWASM binaries embedded.
runtime
The execution environment for rWASM contracts. Provides host functions exposed to smart contracts and manages context such as storage, account data, and precompiled contract calls. Executes rWASM bytecode with deterministic gas accounting and supports both EVM and SVM compatibility layers.
sdk
Main library for developing contracts that run on the Fluentbase runtime. Provides the core SharedAPI trait, entrypoint macros, and a collection of types used by contracts. Includes basic_entrypoint! macro, SharedAPI trait for storage and context access, and re-exports common primitive types.
sdk-derive
Procedural macros for Fluentbase smart contract development. Generates boilerplate code and provides Solidity compatibility through Contract derivation, router method dispatch, client generation, EVM-compatible storage layout, and Solidity interface conversions.
svm
Implementation of the Solana Virtual Machine adapted for Fluentbase. Provides an alternative execution environment alongside the EVM for running Solana-style programs. Includes instruction processors, loader logic, and account handling compatible with the Solana model.
svm-shared
Common types and utilities used across the Fluentbase SVM crates. Provides shared logic between the SVM runtime and Solana compatibility precompiles, including bincode helpers and test structures to avoid code duplication.
testing
Testing utilities for Fluentbase contracts. Embeds the runtime and provides helpers for executing rWASM modules in unit tests. Includes the include_this_wasm! macro for contracts to include their own WASM binary during tests, and EVM test harness powered by forked revm.
types
Primitive types and data structures shared across all Fluentbase crates. Exposes Address and Bytes types along with runtime context objects and helper enums for error handling and contract execution. Most types are no_std friendly and re-export rwasm core primitives.
3.
e2e
A
set of e2e tests
for testing EVM transition and other
Wasm features.
Contract Development Patterns
Fluentbase provides several development patterns depending on your use case and complexity requirements:
1. Simple Contracts
For basic contracts that don't require complex routing or storage:
#![cfg_attr(target_arch =
"wasm32"
, no_std)]
extern
crate
fluentbase_sdk
;
use
fluentbase_sdk
::
{
basic_entrypoint
,
derive
::
Contract
,
SharedAPI
}
;
#[derive(Contract)]
struct
GREETING
<
SDK
>
{
sdk
:
SDK
,
}
impl
<
SDK
:
SharedAPI
>
GREETING
<
SDK
>
{
fn
deploy
(
&
mut
self
)
{
// any custom deployment logic here
}
fn
main
(
&
mut
self
)
{
// write "Hello, World" message into output
self
.
sdk
.
write
(
"Hello, World"
.
as_bytes
(
)
)
;
}
}
basic_entrypoint!
(
GREETING
)
;
2. Router-Based Contracts
For contracts that need to handle multiple function calls with automatic parameter decoding:
#![cfg_attr(target_arch =
"wasm32"
, no_std, no_main)]
extern
crate
alloc
;
extern
crate
fluentbase_sdk
;
use
alloc
::
string
::
String
;
use
fluentbase_sdk
::
{
basic_entrypoint
,
derive
::
{
router
,
Contract
}
,
SharedAPI
,
}
;
#[derive(Contract)]
struct
App
<
SDK
>
{
sdk
:
SDK
,
}
pub
trait
RouterAPI
{
fn
greeting
(
&
self
,
message
:
String
)
->
String
;
fn
custom_greeting
(
&
self
,
message
:
String
)
->
String
;
}
#[router(mode =
"solidity"
)]
impl
<
SDK
:
SharedAPI
>
RouterAPI
for
App
<
SDK
>
{
#[function_id(
"greeting(string)"
)]
fn
greeting
(
&
self
,
message
:
String
)
->
String
{
message
}
#[function_id(
"customGreeting(string)"
)]
fn
custom_greeting
(
&
self
,
message
:
String
)
->
String
{
message
}
}
impl
<
SDK
:
SharedAPI
>
App
<
SDK
>
{
pub
fn
deploy
(
&
self
)
{
// any custom deployment logic here
}
}
basic_entrypoint!
(
App
)
;
3. Storage-Enabled Contracts
For contracts that need persistent state management with Solidity-compatible storage:
#![cfg_attr(target_arch =
"wasm32"
, no_std, no_main)]
extern
crate
alloc
;
extern
crate
fluentbase_sdk
;
use
alloc
::
vec
::
Vec
;
use
alloy_sol_types
::
{
sol
,
SolEvent
}
;
use
fluentbase_sdk
::
{
basic_entrypoint
,
derive
::
{
router
,
solidity_storage
}
,
Address
,
Bytes
,
ContextReader
,
SharedAPI
,
B256
,
U256
,
}
;
pub
trait
ERC20API
{
fn
symbol
(
&
self
)
->
Bytes
;
fn
name
(
&
self
)
->
Bytes
;
fn
decimals
(
&
self
)
->
U256
;
fn
total_supply
(
&
self
)
->
U256
;
fn
balance_of
(
&
self
,
address
:
Address
)
->
U256
;
fn
transfer
(
&
mut
self
,
to
:
Address
,
value
:
U256
)
->
U256
;
fn
allowance
(
&
self
,
owner
:
Address
,
spender
:
Address
)
->
U256
;
fn
approve
(
&
mut
self
,
spender
:
Address
,
value
:
U256
)
->
U256
;
fn
transfer_from
(
&
mut
self
,
from
:
Address
,
to
:
Address
,
value
:
U256
)
->
U256
;
}
// Define events for contract interactions
sol!
{
event
Transfer
(
address indexed from
,
address indexed to
,
uint256 value
)
;
event
Approval
(
address indexed owner
,
address indexed spender
,
uint256 value
)
;
}
// Solidity-compatible storage layout
solidity_storage!
{
mapping
(
Address
=>
U256
)
Balance
;
mapping
(
Address
=>
mapping
(
Address
=>
U256
)
)
Allowances
;
}
#[derive(Contract)]
struct
ERC20
<
SDK
>
{
sdk
:
SDK
,
name
:
&
'static
str
,
symbol
:
&
'static
str
,
}
#[router(mode =
"solidity"
)]
impl
<
SDK
:
SharedAPI
>
ERC20API
for
ERC20
<
SDK
>
{
fn
symbol
(
&
self
)
->
Bytes
{
self
.
symbol
.
as_bytes
(
)
.
to_vec
(
)
.
into
(
)
}
fn
name
(
&
self
)
->
Bytes
{
self
.
name
.
as_bytes
(
)
.
to_vec
(
)
.
into
(
)
}
fn
decimals
(
&
self
)
->
U256
{
U256
::
from
(
18
)
}
fn
total_supply
(
&
self
)
->
U256
{
U256
::
from
(
1_000_000u64
*
10u64
.
pow
(
18
)
)
}
fn
balance_of
(
&
self
,
address
:
Address
)
->
U256
{
Balance
::
get
(
&
self
.
sdk
,
address
)
}
fn
transfer
(
&
mut
self
,
to
:
Address
,
value
:
U256
)
->
U256
{
let
from
=
self
.
sdk
.
msg_sender
(
)
;
let
from_balance
=
Balance
::
get
(
&
self
.
sdk
,
from
)
;
assert!
(
from_balance
>=
value
,
"insufficient balance"
)
;
Balance
::
set
(
&
mut
self
.
sdk
,
from
,
from_balance
-
value
)
;
Balance
::
set
(
&
mut
self
.
sdk
,
to
,
Balance
::
get
(
&
self
.
sdk
,
to
)
+
value
)
;
Transfer
{
from
,
to
,
value
}
.
emit
(
&
mut
self
.
sdk
)
;
U256
::
from
(
1
)
// Return true as U256
}
// Additional methods implementation...
}
basic_entrypoint!
(
ERC20
)
;
Development Workflow
Fluent development typically follows this workflow:
Project Setup
Begin by initializing a new project using
gblend
— a CLI tool built on top of Foundry and tailored for the Fluent Network. It supports both Solidity and Rust-based contracts.
Contract Development
You can extend existing Solidity contracts with additional functionality written in Rust. This enables more expressive and flexible logic than Solidity alone allows. Or create standalone Rust contract.
Testing
Write unit tests directly in Rust using
HostTestingContext
. This allows you to validate contract logic before deploying it on-chain. Use
gblend
to test interoperability.
Build
Use Gblend to compile your Rust contracts to WASM artifacts compatible with the Fluent runtime.
Deployment
Use Gblend to deploy the generated WASM binaries to the Fluent Network. Verification and scripting flows are also supported.
For more detailed instructions, see:
Gblend Guide
— CLI usage and project templates
Fluent Development Guide
— best practices, patterns, and architecture
Current Features and Limitations
Features
Full EVM compatibility through ABI encoding
Solidity-compatible storage layout
Automatic function routing and parameter decoding
Event emission and logging
Cross-contract calls
Comprehensive testing framework
Limitations
No floating-point operations support (planned for future releases)
no_std
environment requires careful crate selection
Limited to WASM-compatible libraries
Next Steps
This overview provides the foundation for building with the Fluentbase SDK. For detailed information on specific
features:
Router System
: Learn about automatic method dispatch and function selectors
Storage Management
: Understand Solidity-compatible storage patterns
Codec System
: Explore encoding/decoding for complex data types
Client Generation
: Build contract inte프로젝트로 돌아가기