Web Requests, Automation and Alerts.

Learn how to send web requests from a Zephyr program.

Automation that responds immediately to on-chain circumnstances is extremely common for both developers, traders, or even generic purpose users.

Mercury allows you to build your automation workflows directly within a zephyr program. You'll be able to build transactions/payloads and send http requests, either directly to a tx submission system (e.g Horizon) or to a callback backend that then further handles the provided payload.

Another common use case are alerts, which are also enabled thorugh web requests (e.g a request to discord's API):

fn send_message(env: &EnvClient, source: ScVal, amount: ScVal) {
    let source = {
        let ScVal::Address(address) = source else { panic!() };
        address.to_string()
    };
    let key = env!("DISCORD_API");
    let body = format!(
        r#"{{"content": "{}"}}"#,
        format!(
            "New large deposit of {:?} XLM from {} on xycLoans testnet XLM pool.",
            amount, source
        )
    );
    env.send_web_request(AgnosticRequest {
        body: Some(body),
        url: "https://discordapp.com/api/channels/1234475897092968459/messages".into(),
        method: zephyr_sdk::Method::Post,
        headers: vec![
            ("Content-Type".into(), "application/json".into()),
            ("Authorization".into(), format!("Bot {}", key)),
        ],
    })
}

The above example is taken from xycLoan's deposits discord bot.


Resources

Here are additional automation resources:

Last updated