ic-radix-rs
A Rust implementation of the Radix Gateway API Client for the Internet Computer.
Features
- Perform API Calls to the Radix Gateway API within canisters
Usage
Add the following to your Cargo.toml:
[dependencies]
ic-radix-rs = "0.0.1"
Example
use candid::{export_service, CandidType, Deserialize};
use ic_cdk::api::management_canister::http_request::{HttpResponse, TransformArgs};
use ic_radix_rs::apis::transaction_api::transaction_construction;
use serde::Serialize;
#[ic_cdk::update]
async fn example_transaction_construction() -> Response {
let cfg = ic_radix_rs::apis::configuration::Configuration::new();
let result = transaction_construction(&cfg).await.unwrap();
Response {
network: result.ledger_state.network,
state_version: result.ledger_state.state_version,
proposer_round_timestamp: result.ledger_state.proposer_round_timestamp,
epoch: result.ledger_state.epoch,
round: result.ledger_state.round,
}
}
#[ic_cdk::query]
fn transform(args: TransformArgs) -> HttpResponse {
args.response
}
#[derive(CandidType, Deserialize, Serialize)]
struct Response {
pub network: String,
pub state_version: i64,
pub proposer_round_timestamp: String,
pub epoch: i64,
pub round: i64,
}
Start a local replica:
dfx start
Deploy the canister:
dfx deploy
Call the canister:
dfx canister call examples_backend example_transaction_construction
Then you will get a response like this:
(
record {
state_version = 84_154_806 : int64;
proposer_round_timestamp = "2024-05-16T07:31:34.07Z";
network = "mainnet";
epoch = 98_981 : int64;
round = 161 : int64;
},
)