#[contractimpl]
Expand description
Exports the publicly accessible functions to the Soroban environment.
Functions that are publicly accessible in the implementation are invocable by other contracts, or directly by transactions, when deployed.
ยงExamples
Define a contract with one function, hello
, and call it from within a test
using the generated client.
use soroban_sdk::{contract, contractimpl, vec, symbol_short, BytesN, Env, Symbol, Vec};
#[contract]
pub struct HelloContract;
#[contractimpl]
impl HelloContract {
pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> {
vec![&env, symbol_short!("Hello"), to]
}
}
#[test]
fn test() {
let env = Env::default();
let contract_id = env.register(HelloContract, ());
let client = HelloContractClient::new(&env, &contract_id);
let words = client.hello(&symbol_short!("Dev"));
assert_eq!(words, vec![&env, symbol_short!("Hello"), symbol_short!("Dev"),]);
}