| Crates.io | inf-circle-sdk |
| lib.rs | inf-circle-sdk |
| version | 0.2.6 |
| created_at | 2025-10-11 19:09:05.781878+00 |
| updated_at | 2025-12-05 19:06:38.212937+00 |
| description | Rust SDK for Circle's API with clean separation of read and write operations |
| homepage | https://github.com/Inferenco/inf-circle-sdk |
| repository | https://github.com/Inferenco/inf-circle-sdk |
| max_upload_size | |
| id | 1878460 |
| size | 660,113 |
A comprehensive Rust SDK for Circle's API, designed with a clean separation between write (CircleOps) and read (CircleView) operations. This library provides a type-safe, async-first interface to interact with Circle's powerful developer APIs.
The SDK is split into two main components:
CircleOps: Handles all write operations (POST, PUT, PATCH) that require entity-level authentication. It uses an entity secret to sign requests and provides a secure way to create and manage resources.CircleView: Handles all read operations (GET) that do not require entity-level authentication. It provides a simple interface to query data from the Circle API.This separation ensures that read-only processes do not require access to sensitive entity secrets, enhancing security and simplifying access control.
CircleOps for writes, CircleView for readstokio for non-blocking, asynchronous operationsAdd this to your Cargo.toml:
[dependencies]
inf-circle-sdk = "0.1.8"
Create a .env file in your project root with the following variables:
CIRCLE_BASE_URL="https://api.circle.com"
CIRCLE_API_KEY="YOUR_API_KEY"
CIRCLE_ENTITY_SECRET="YOUR_ENTITY_SECRET_HEX"
CIRCLE_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\nYOUR_RSA_PUBLIC_KEY_IN_PEM_FORMAT\n-----END PUBLIC KEY-----"
CIRCLE_WALLET_SET_ID="YOUR_WALLET_SET_ID"
Note:
CIRCLE_API_KEY is used for API authentication in the Authorization headerCIRCLE_ENTITY_SECRET should be the hex-encoded entity secretCIRCLE_PUBLIC_KEY should be the RSA public key in PEM format (PKCS#1 or PKCS#8)use inf_circle_sdk::{
circle_ops::circler_ops::CircleOps,
dev_wallet::{dto::AccountType, ops::create_dev_wallet::CreateDevWalletRequestBuilder},
types::Blockchain,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ops = CircleOps::new(None)?;
let wallet_set_id = std::env::var("CIRCLE_WALLET_SET_ID")?;
let builder = CreateDevWalletRequestBuilder::new(
wallet_set_id,
vec![Blockchain::EthSepolia]
)?
.account_type(AccountType::Sca)
.count(1)
.build();
let response = ops.create_dev_wallet(builder).await?;
println!("Created wallet: {}", response.wallets[0].address);
Ok(())
}
use inf_circle_sdk::{
circle_view::circle_view::CircleView,
dev_wallet::views::query::QueryParamsBuilder,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let view = CircleView::new()?;
let params = QueryParamsBuilder::new().build();
let balances = view.get_token_balances("wallet-id", params).await?;
for balance in balances.token_balances {
println!("{}: {}", balance.token.symbol.unwrap_or_default(), balance.amount);
}
Ok(())
}
use inf_circle_sdk::{
circle_ops::circler_ops::CircleOps,
dev_wallet::{
dto::FeeLevel,
ops::create_transfer_transaction::CreateTransferTransactionRequestBuilder,
},
types::Blockchain,
};
use uuid::Uuid;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ops = CircleOps::new(None)?;
let builder = CreateTransferTransactionRequestBuilder::new("wallet-id".to_string())
.destination_address("0x1234...".to_string())
.amounts(vec!["0.1".to_string()])
.blockchain(Blockchain::EthSepolia)
.fee_level(FeeLevel::Medium)
.idempotency_key(Uuid::new_v4().to_string())
.build();
let response = ops.create_dev_transfer_transaction(builder).await?;
println!("Transaction ID: {}", response.id);
Ok(())
}
The SDK includes 12 comprehensive examples covering all major features:
Run any example with:
cargo run --example wallet_balances_example
The SDK includes comprehensive integration tests. To run them, you'll need to set up your environment:
CIRCLE_BASE_URL="https://api.circle.com"
CIRCLE_API_KEY="YOUR_API_KEY"
CIRCLE_ENTITY_SECRET="YOUR_ENTITY_SECRET_HEX"
CIRCLE_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\nYOUR_RSA_PUBLIC_KEY\n-----END PUBLIC KEY-----"
CIRCLE_WALLET_SET_ID="YOUR_WALLET_SET_ID"
CIRCLE_TEMPLATE_ID="YOUR_CONTRACT_TEMPLATE_ID"
The notification subscription tests require a publicly accessible webhook endpoint because Circle validates endpoints by making HTTP requests to them.
Quick Setup:
# Use the helper script (auto-detects tunnelto or ngrok)
./scripts/start_webhook_server.sh
# Export the URL shown and run tests
export CIRCLE_TEST_WEBHOOK_URL="<url-from-script>"
cargo test test_notification_subscriptions_crud
For detailed webhook setup options (tunnelto, ngrok, webhook.site, custom subdomains), see scripts/README.md.
If you don't set CIRCLE_TEST_WEBHOOK_URL, the notification subscription test will be automatically skipped.
# Run all tests
cargo test
# Run specific test
cargo test test_notification_subscriptions_crud
# Run with output
cargo test -- --nocapture
Contributions are welcome! Please see CONTRIBUTING.md for details.
This project is licensed under the MIT License - see the LICENSE file for details.