8 releases

new 0.1.7 Feb 8, 2025
0.1.6 Jan 25, 2025
0.1.5 Oct 7, 2024
0.1.4 Jun 20, 2024
0.1.2 Jun 18, 2023

#7 in Magic Beans

Download history 10/week @ 2024-11-04 1/week @ 2024-12-09 84/week @ 2025-01-20 33/week @ 2025-01-27 112/week @ 2025-02-03

229 downloads per month
Used in blockless-web-cgi

MIT/Apache

42KB
736 lines

Blockless-sdk-rust

How to build

  1. Install the rust with rustup, please visit the site 'https://rustup.rs/'.

  2. Use follow command for build the project.

$ cargo build

HTTP example

use blockless_sdk::*;
use json;

fn main() {
    let opts = HttpOptions::new("GET", 30, 10);
    let http = BlocklessHttp::open("https://demo.bls.dev/tokens", &opts);
    let http = http.unwrap();
    let body = http.get_all_body().unwrap();
    let body = String::from_utf8(body).unwrap();
    let tokens = match json::parse(&body).unwrap() {
        json::JsonValue::Object(o) => o,
        _ => panic!("must be object"),
    };
    let tokens = match tokens.get("tokens") {
        Some(json::JsonValue::Array(tokens)) => tokens,
        _ => panic!("must be array"),
    };
    tokens.iter().for_each(|s| {
        println!("{:?}", s.as_str());
    });
}

Install from crates.io

cargo add blockless-sdk

Examples

Examples are in the examples directory.

Coingecko Oracle

# Build example
cargo build --release --target wasm32-wasip1 --example coingecko_oracle

# Run example with blockless runtime
echo "bitcoin" | runtime target/wasm32-wasip1/release/examples/coingecko_oracle.wasm --permission https://api.coingecko.com/

HTTP

# Build example
cargo build --release --target wasm32-wasip1 --example httpbin

# Run example with blockless runtime
~/.bls/runtime/bls-runtime target/wasm32-wasip1/release/examples/httpbin.wasm --permission http://httpbin.org/anything

Examples list

Example Description Browser runtime support Native runtime support
coingecko_oracle Coingecko Oracle to query price of bitcoin from coingecko
httpbin HTTP to query anything from httpbin
llm LLM to chat with Llama-3.1-8B-Instruct-q4f32_1-MLC and SmolLM2-1.7B-Instruct-q4f16_1-MLC models

Dependencies

~0.4–1MB
~23K SLoC