EXPLORE ON THE APP
1// slightly stripped down or modified version of the impl for simplicity. Also, pardon the formatting.
2#[derive(DatabaseDerive, Clone)]
3#[with_name("curr_seq")]
4struct Sequence {
5 pub current: u32,
6}
7
8#[no_mangle]
9pub extern "C" fn on_close() {
10 let env = EnvClient::new();
11 let sequence = Sequence {
12 current: env.reader().ledger_sequence()
13 };
14 if let Some(last) = Sequence::read_to_rows(&env).iter().find(|x| {
15 x.current == sequence.current - 1
16 }) {
17 env.update().column_equal_to_xdr("current", &last.current).execute(&sequence);
18 } else {
19 sequence.put(&env)
20 }
21}
22
23
Define your custom ingestion logic as well as your data structures on the database and let us take care of the rest. No need to run any infrastructure!
1// slightly stripped down or modified version of the impl for simplicity. Also, pardon the formatting.
2#[derive(Serialize, Deserialize)]
3pub struct ColorMintRequest {
4 source: String,
5 colors: Vec<ColorClient>,
6}
7#[no_mangle]
8pub extern "C" fn simulate_color_mint() {
9 let env = EnvClient::empty();
10 let request: ColorMintRequest = env.read_request_body();
11 let (source, source_addr) = /*source from request*/ ;
12 let function_name = Symbol::new(&env.soroban(), "colors_mine");
13 let mut colors = Map::new(&env.soroban());
14 for color in request.colors {
15 colors.set(color.color, color.amount);
16 }
17 let resp = env.simulate(
18 source, zephyr_sdk::soroban_sdk::xdr::HostFunction::InvokeContract(InvokeContractArgs {
19 contract_address: zephyr_sdk::soroban_sdk::xdr::ScAddress::Contract(Hash(CONTRACT_ADDRESS)),
20 function_name,
21 args: vec![env.to_scval(source_addr), env.to_scval(colors)].try_into().unwrap()})).unwrap();
22 env.conclude(resp)
23}
Write custom RPC functionalities using rust and the native soroban sdk as typesystem.
1// Build fully-customizable multi-chart dashboards.
2//
3#[no_mangle]
4pub extern "C" fn dashboard() {
5 let env = EnvClient::empty();
6 let chart = {
7 let supplies = Supply::read_to_rows(&env);
8 let collaterals = Collateral::read_to_rows(&env);
9 let borroweds = Borrowed::read_to_rows(&env);
10 env.log().debug("Aggregating data", None);
11 let aggregated = aggregate_data(supplies, collaterals, borroweds);
12 env.log().debug("Data aggregated", None);
13 let chart = create_chart(&env, aggregated);
14
15 env.log().debug("chart built", None);
16 chart
17 };
18
19 env.conclude(&chart)
20}
21
22
23
Create fully-programmable multi-chart dashboards.
1// slightly stripped down or modified version of the impl for simplicity. Also, pardon the formatting.
2fn send_message(env: &EnvClient, source: ScVal, amount: ScVal) {
3 // get key from env + build body.
4 env.send_web_request(AgnosticRequest {
5 body: Some(body),
6 url: "https://discordapp.com/api/channels/1234475897092968459/messages".into(),
7 method: zephyr_sdk::Method::Post,
8 headers: vec![("Content-Type".into(), "application/json".into()),
9 ("Authorization".into(), format!("Bot {}", key))]})
10}
11#[no_mangle]
12pub extern "C" fn on_close() {
13 let env = EnvClient::new();
14 let contract_events: Vec<ContractEvent> = env.reader().soroban_events().into_iter()
15 .filter(|event| event.contract_id == Some(Hash(CONTRACT_ADDRESS))).collect();
16 for event in contract_events {
17 if Symbol::new(&env.soroban(), "deposit") == env.from_scval(&event.topics[0])
18 && 10_000_000_000 <= env.from_scval::<i128>(&event.data) {
19 env.log().debug("got deposit larger than 1000 XLM", None);
20 send_message(&env, event.topics[1].clone(), event.data)
21 }
22 }
23}
Build alerts and monitoring systems with access to latest ledger data, and perform web requests directly from the program's logic.
1// slightly stripped down or modified version of the impl for simplicity. Also, pardon the formatting.
2
3// make a subscription to a contract event with a certain first topic:
4
5curl -X POST \
6 -H "Content-Type: application/json" \
7 -H "Authorization: Bearer $JWT_TOKEN" \
8 -d '{
9 "contract_id": "CONTRACT_ID",
10 "topic1": "SOME_SCVAL_XDR",
11 }' \
12 https://api.mercurydata.app/event
13
14
15// make the request to the graphql API:
16
17curl -X POST https://api.mercurydata.app/graphql ...
18
19
20
21
22
23
For simpler use cases subscribe to the specific data you need and make them available for querying afterwards.
mercury-cli deploy
. Furthermore, we have hardwired our VM to Soroban, allowing you to work within the same native environment you're writing contracts in.New Feature! You can now manage your Zephyr program and its logs directly from the Mercury webapp.