Mercury Documentation
  • Get Started with Mercury
    • Pricing
    • Endpoints
    • Authentication
  • The Definitive Guide to Understanding The Mercury's Stack Vision
  • Retroshades
    • Introduction to Retroshades
    • Get Started
      • Importing the Retroshades SDK
      • Writing and Emitting Retroshades
      • Deploying to Mercury Retroshades
      • Querying Retroshades
  • Zephyr: Full Customization
    • Introduction
    • General concepts
      • Zephyr Programs
      • Accessing the Ledger: Contract Entries
      • Accessing the Ledger Meta: Contract Events
      • Database Interactions
      • Create Custom Callable APIs: Serverless Functions
      • Catchups
      • Using Soroban inside Zephyr
    • Quickstart
    • Learn
      • Introduction to Mercury's Cloud and the Zephyr Stack
      • Get Started: Set Up and Manage the Project
        • Create the Project
        • Writing the Program
        • Local Testing
        • Deploy
        • Data catchups/backfill
        • Monitor Execution
        • Querying
      • Database Interactions
        • Zephyr.toml: Define the Tables Structure
        • Understanding Database Interactions
        • Database Operations
      • Accessing the Ledger
      • Accessing Ledger Transition: Soroban Events
      • Working with Contract Custom Types
      • Working with Soroban SDK Types
      • Web Requests, Automation and Alerts.
      • Zephyr.toml Extensions: Indexes And Dashboard
      • Reading From Indexes/External Tables
      • Custom APIs - Serverless Functions
        • General Concepts
        • Custom RPC-alike Endpoints
        • Querying APIs for Composable Data
      • Data Catchups/Backfill
      • Custom Dashboards
        • Creating the Dashboard
        • Plotting: Simple
        • Complex Plotting
    • Support
  • Mercury "Classic"
    • Subscriptions
      • API Definition
    • Queries
      • Contract Events
      • Contract Data Entry Updates
      • Stellar Operations, Balances, and Account Objects
  • TUTORIALS
    • Zephyr
      • Self-hosting Zephyr
      • No-RPC Dapp
      • Indexing a DeFi liquidity pool (Blend)
      • Building a Secure DeFi Real-Time Bot Through Smart Accounts
      • Monitoring Large Deposits with Zephyr and Sending Web Alerts
    • Mercury Classic
      • Index and query contract events
Powered by GitBook
On this page
  1. Zephyr: Full Customization
  2. Learn

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)),
        ],
    })
}

Resources

Here are additional automation resources:

PreviousWorking with Soroban SDK TypesNextZephyr.toml Extensions: Indexes And Dashboard

Last updated 8 months ago

The above example is taken from .

xycLoan's deposits discord bot
https://blog.xycloo.com/blog/blend-bot-with-zephyr-and-smart-accounts
https://heytdep.github.io/post/20/post.html