#[client]Expand description
Client macro for type-safe interaction with Fluentbase contracts.
Generates a client struct and methods from a trait definition, handling contract calls, parameter encoding, and result decoding automatically.
§Usage
ⓘ
#[client(mode = "solidity")]
trait TokenInterface {
#[function_id("balanceOf(address)")]
fn balance_of(&self, owner: Address) -> U256;
#[function_id("transfer(address,uint256)")]
fn transfer(&mut self, to: Address, amount: U256) -> bool;
}
// Using the generated client
let mut client = TokenInterfaceClient::new(sdk);
// Call contract methods with standard parameters
let balance = client.balance_of(
token_address, // contract address
U256::zero(), // value to send (none)
50000, // gas limit
my_address // method-specific parameters
);§Generated Code
For a trait named TokenInterface, generates:
TokenInterfaceClient<SDK>struct with anew(sdk)constructor- Method implementations that append common parameters:
rust,ignore fn method_name( &mut self, contract_address: Address, // Target contract value: U256, // Native tokens to send gas_limit: u64, // Maximum gas ...original_parameters // From trait definition ) -> original_return_type
§Features
- Automatic encoding/decoding of parameters and return values
- Runtime safety checks for insufficient funds or gas
- Compatible with router when using the same encoding mode
- Preserves method signatures from the trait definition
§Attributes
- mode: Encoding mode
"solidity": Full EVM compatibility (default)"fluent": Optimized encoding for WASM