ic-agent-canister-runtime

Crates.ioic-agent-canister-runtime
lib.rsic-agent-canister-runtime
version0.1.1
created_at2025-11-24 09:17:59.873431+00
updated_at2025-12-09 12:25:00.492941+00
descriptionImplementation of a canister runtime of the Internet Computer for `ic-agent`
homepagehttps://github.com/dfinity/canhttp
repositoryhttps://github.com/dfinity/canhttp
max_upload_size
id1947561
size89,918
(dfinity-publish)

documentation

https://docs.rs/ic-agent-canister-runtime

README

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.

Commit count: 0

cargo fmt