#merkle #integration #transaction #service #seamless #sdk

merkle-sdk

A Rust library for seamless integration with Merkle's services

7 releases

0.0.7 Mar 11, 2024
0.0.6 Feb 1, 2024
0.0.5 Oct 30, 2023
0.0.3 Sep 8, 2023

#484 in Database interfaces

Download history 107/week @ 2024-01-20 101/week @ 2024-01-27 38/week @ 2024-02-03 15/week @ 2024-02-10 92/week @ 2024-02-17 19/week @ 2024-02-24 2/week @ 2024-03-02 186/week @ 2024-03-09 15/week @ 2024-03-16 1/week @ 2024-03-23 31/week @ 2024-03-30 19/week @ 2024-04-06 3/week @ 2024-04-13 110/week @ 2024-04-20 120/week @ 2024-04-27 19/week @ 2024-05-04

252 downloads per month

MIT/Apache

18KB
276 lines

merkle Rust SDK

The merkle SDK is a great way to access our products.

Install

Add the following to your cargo.toml file:

[dependencies]
merkle-sdk = "0.0.7"

Examples

Examples are organized into individual crates under the /examples folder. You can run any of the examples by executing:

# cargo run -p <example-crate-name> --example <name>
cargo run -p examples-transactions --example transactions

Listen to transactions

Get an API key for free at mbs.merkle.io.

use merkle_sdk::prelude::Connection;
use futures::StreamExt;

#[tokio::main]
async fn main() {
    let api_key = "sk_mbs_a35bf8ac729f9992a4319427df6b564f";
    if let Ok(conn) = Connection::from_key(api_key).await {
        let mut stream = conn.into_stream();
        while let Some(txn) = stream.next().await {
            println!("{txn:?}");
        }
     }
}

This library supports connections to different chains. This can be achieved using out of box builder functions:

use std::env;

use futures::StreamExt;
use merkle_sdk::{prelude::Connection, transactions::ChainId};

#[tokio::main]
async fn main() {
    let api_key = "sk_mbs_a35bf8ac729f9992a4319427df6b564f"

    // Create a Mainnet connection
    let _conn_res = Connection::with_key(&api_key)
        .mainnet()
        .build()
        .await;

    // Create a Polygon connection
    let _conn_res = Connection::with_key(&api_key)
        .polygon()
        .build()
        .await;

    // Create a BSC connection
    let _conn_res = Connection::with_key(&api_key)
        .bsc()
        .build()
        .await;

    // Create a connection based on chain id
    let conn_res = Connection::with_key(&api_key)
        .chain(ChainId::Id(137))
        .build()
        .await;

    if let Ok(conn) = conn_res {
        let mut stream = conn.into_stream();
        while let Some(txn) = stream.next().await {
            println!("{txn:?}");
        }
     }
}

Dependencies

~28–45MB
~832K SLoC