Skip to content

sudoblockio/sb-stack-demo

Repository files navigation

sb-stack-demo

Modern applications are built on top of a variety of different protocols each of which require support from SDKs in every language - reimplementing the same underlying logic and types over and over again. sb-stack unifies these efforts into a single composable rust core for building protocol specific clients with bindings into higher level languages like python and typescript. While the real benefits are in maintaining 1 package vs 1 per language (and per chain), sb-stack also ships with a universal middleware ecosystem (retries, telemetry, load balancing) and a core that is 5 times faster than native language implementations like axios, fetch, and httpx.

Documentation Index

Transports

Protocols

Clients

Quick Examples

HTTP Transport

Rust

use sb_stack_transport_http::{
  HttpTransport,
  Http1TransportConfig,
  HttpTransportRequestPacket
};

async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let base_url = "https://httpbin.org".parse()?;
    let mut transport = HttpTransport::new(
      base_url.clone(), Http1TransportConfig::default(), None
      );
    transport.connect().await?;
    let mut request = HttpTransportRequestPacket::new(http::Method::GET);
    request.set_url(Some(base_url.join("/get")?));
    let response = transport.call(request).await?;
    Ok(())
}

Python

from sb_http_client import HttpClient

async def example():
    client = HttpClient("https://httpbin.org")
    response = await client.get("/get")
    print(f"Status: {response.status}")

Typescript

import { HttpClient } from 'sb-http-client';

async function example() {
    const client = new HttpClient({ baseURL: 'https://httpbin.org' });
    const response = await client.get('/get');
    console.log('Status:', response.status);
}

Eth Client

Rust

use sb_eth_jsonrpc_client::EthJsonrpcClient;

async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let client = EthJsonrpcClient::new("https://eth.rpc.sudoblock.io");
    client.connect().await?;
    let block = client.eth().get_block_by_number(12345.into(), true).await?;
    println!("Block: {}", block.number);
    client.close().await?;
    Ok(())
}

Python

from sb_eth_jsonrpc_client import EthJsonrpcClient

async def example():
    client = EthJsonrpcClient("https://eth.rpc.sudoblock.io")
    await client.connect()
    block = await client.eth().get_block_by_number(12345, True)
    print(f"Block: {block.number}")
    await client.close()

Typescript

import { EthJsonrpcClient } from 'sb-eth-jsonrpc-client';

async function example() {
    const client = new EthJsonrpcClient("https://eth.rpc.sudoblock.io");
    await client.connect();
    const block = await client.eth().getBlockByNumber(12345, true);
    console.log(`Block: ${block.number}`);
    await client.close();
}

About

sudoblock stack demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published