5 releases
new 0.1.16 | Dec 16, 2024 |
---|---|
0.1.15 | Dec 10, 2024 |
0.1.14 | Nov 1, 2024 |
0.1.13 | Nov 1, 2024 |
0.1.12 | Oct 29, 2024 |
#1 in #yes
184 downloads per month
Used in clique-cli
450KB
1.5K
SLoC
Clique Client SDK
The Clique Client SDK is an open-source library that enables users to interact with the Clique Network. We currently support Rust, NodeJS, and Web.
Clique Query
Clique supports JSON-RPC-styled queries.
Field | description | required |
---|---|---|
id | Unique query ID | Yes |
method | Task name | Yes |
params | Task input | Yes |
input_types | Task input types | Yes |
custom_types | Task custom types | Yes |
Rust
How to use
Add this dependency to your Cargo.toml
clique-client-sdk = { git = "https://github.com/CliqueOfficial/clique-protocol-sdk" }
tokio = { version = "1.38.0", features = ["full"] }
use std::time::Duration;
use clique_client_sdk::CliqueClient;
use serde_json::json;
#[tokio::main]
async fn main() {
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
.with_max_level(tracing::Level::INFO)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
// The endpoint for the Clique Network
let endpoint = "https://localhost:8000";
// Interval for polling the Clique Network to retrieve results
let polling_interval = Duration::from_millis(500);
// Maximum number of retries for network errors
let retry_num = 5;
// If the user creates a query with the same id, method, and params, the client will return the result of the existing query when the value is true; otherwise, the client will throw an exception.
let allow_exist_query = false;
// Trusted mr_enclaves of clique-kernel
let trusted_enclaves = Some(vec![
"5d474d0e8b431764ddf3db67b1028399d42301340ceb4abc840c4dee426e0d9d".to_string(),
]);
// Trusted mr_signers of clique-kernel
let trusted_signers = Some(vec![
"6601c448087c060907a3c71f1c10fbae92260bef8ac37258b2314338042dadb4".to_string(),
]);
// Create a CliqueClient with custom configuration for polling interval, retry limit, allow_exist_query, trusted_enclaves, trusted_signers
let client = CliqueClient::with_config(
endpoint,
polling_interval,
retry_num,
allow_exist_query,
trusted_enclaves,
trusted_signers,
)
.unwrap();
// Alternatively, create a CliqueClient with default configuration
// let client = CliqueClient::new(endpoint, trusted_enclaves, trusted_signers).unwrap();
// Create a single query using `serde_json::json`
let json_query = json!({
"id": 1,
"method": "clique_fibonacci",
"params": {"n": "10"},
"input_types": {"n": "u256"},
"custom_types": {}
});
// Run the query and wait for the result
let result = client.run_query(json_query).await.unwrap();
println!("result: {:?}", result);
// Create batch query using `serde_json::json`
let json_query = json!([
{"id": 2, "method": "clique_fibonacci", "params": {"n": "11"}, "input_types": {"n": "u256"}, "custom_types": {}},
{"id": 3, "method": "clique_fibonacci", "params": {"n": "12"}, "input_types": {"n": "u256"}, "custom_types": {}}
]);
// Run the query and wait for the result
let result = client.run_query(json_query).await.unwrap();
println!("result: {:?}", result);
}
Node.js
https://www.npmjs.com/package/@cliqueofficial/clique-client-sdk-node
Web
https://www.npmjs.com/package/@cliqueofficial/clique-client-sdk-web
Dependencies
~25–38MB
~685K SLoC