ic-agent-canister-runtime 0.1.2

Implementation of a canister runtime of the Internet Computer for `ic-agent`
Documentation

Internet Computer portal DFinity Forum GitHub license

ic-agent-canister-runtime

Library that implements the ic_canister_runtime crate's Runtime trait using ic-agent. This can be useful when, e.g., contacting a canister via ingress messages instead of via another canister.

Usage

Add this to your Cargo.toml (see crates.io for the latest version):

ic-agent-canister-runtime = "0.1.0"
ic-canister-runtime = "0.1.0"

Then, use the library to abstract your code making requests to canisters as follows:

use ic_agent_canister_runtime::AgentRuntime;
use ic_canister_runtime::Runtime;

let agent = ic_agent::agent::Agent::builder().build().unwrap();
let runtime = AgentRuntime::new(&agent);

// Make a request to the `http_request` example canister's `make_http_post_request` endpoint
// See: https://github.com/dfinity/canhttp/tree/main/examples/http_canister
let http_request_result: String = runtime
    .update_call(canister_id, "make_http_post_request", (), 0)
    .await
    .expect("Call to `http_canister` failed");

assert!(http_request_result.contains("Hello, World!"));
assert!(http_request_result.contains("\"X-Id\": \"42\""));

See the Rust documentation for more details.

License

This project is licensed under the Apache License 2.0.