ICPAgent (Candid v0.1.5) View Source
This module provides a client for the ICP protocol.
Query example
This examples uses the get_latest_sns_version_pretty
method from the SNS-wasm system canister. It's a publicly available method, so no authentication is needed. We're generating a new wallet ad-hoc and using it to query the
canister.
> [versions] = ICPAgent.query("qaa6y-5yaaa-aaaaa-aaafa-cai", DiodeClient.Wallet.new(), "get_latest_sns_version_pretty")
[
[
{"Ledger Index",
"2adc74fe5667f26ea4c4006309d99b1dfa71787aa43a5c168cb08ec725677996"},
{"Governance",
"bd936ef6bb878df87856a0b0c46034a242a88b7f1eeff5439daf6278febca6b7"},
{"Ledger Archive",
"f94cf1db965b7042197e5894fef54f5f413bb2ebc607ff0fb59c9d4dfd3babea"},
{"Swap", "8313ac22d2ef0a0c1290a85b47f235cfa24ca2c96d095b8dbed5502483b9cd18"},
{"Root", "431cb333feb3f762f742b0dea58745633a2a2ca41075e9933183d850b4ddb259"},
{"Ledger",
"25071c2c55ad4571293e00d8e277f442aec7aed88109743ac52df3125209ff45"}
]
]
Call example
Calls and queries both support providing arguments and types in Candid format specification. These are some examples of call structures to give a better understanding of how the types are specified.
# Generating a new private key as identity
> wallet = DiodeClient.Wallet.new()
# Call with passing two blobs as an argument
> [200] = ICPAgent.call(canister_id, wallet, "test_blob_input", [:blob, :blob], ["blob_a", "blob_b"])
# Call with passing a record as an argument
> [3] = ICPAgent.call(canister_id, wallet, "test_record_input", [{:record, {:nat32, :nat32}}], [{1, 2}])
# Call with passing a record with named fields as an argument
> [3] = ICPAgent.call(canister_id, wallet, "test_named_record_input", [{:record, %{a: :nat32, b: :nat32}}], [{a: 1, b: 2}])
# Call with passing a vector of records as an argument
> [200] = ICPAgent.call(canister_id, wallet, "test_vec_input", [{:vec, {:record, {:blob, :blob}}}], [[{"blob_a", "blob_b"}]])
Limits
- Only secp256k1 keys are supported.
- Did files are not supported and instead types for a call/query must be manually specified.
Link to this section Summary
Functions
This function computes the CRC32 checksum of a binary.
This function decodes a textual representation of an ICP Principal identifier into a binary representation.
Implementation of the ICP hash function. It is in the ICP docs usually referred to as H()
.
Implementation of the ICP hash function for a map. It is in the ICP docs usually referred to as hash_of_map
.
This function queries a canister using the ICP query protocol.
This function converts a DiodeClient.Wallet.t() into a DER encoded binary representation of the public key.
This function converts a PEM encoded binary representation of a Secp256k1 curve private key into a DiodeClient.Wallet.t().
This function converts a DiodeClient.Wallet.t() into a binary representation of the public ICP Principal identifier.
This function signs a binary with a DiodeClient.Wallet.t() using the secp256k1 algorithm and the ICP signing scheme.
This function converts a DiodeClient.Wallet.t() into a textual representation of the public ICP Principal identifier.
Link to this section Functions
This function computes the CRC32 checksum of a binary.
This function decodes a textual representation of an ICP Principal identifier into a binary representation.
Example
iex> ICPAgent.decode_textual("bkyz2-fmaaa-aaaaa-qaaaq-cai")
<<128, 0, 0, 0, 0, 16, 0, 1, 1, 1>>
Implementation of the ICP hash function. It is in the ICP docs usually referred to as H()
.
https://internetcomputer.org/docs/current/references/ic-interface-spec
Implementation of the ICP hash function for a map. It is in the ICP docs usually referred to as hash_of_map
.
https://internetcomputer.org/docs/current/references/ic-interface-spec#request-id
This function queries a canister using the ICP query protocol.
Example:
> [versions] = ICPAgent.query("qaa6y-5yaaa-aaaaa-aaafa-cai", DiodeClient.Wallet.new(), "get_latest_sns_version_pretty")
This function converts a DiodeClient.Wallet.t() into a DER encoded binary representation of the public key.
The DER encoded binary representation is the canonical form as used by the ICP in various protocol interactions.
This function converts a PEM encoded binary representation of a Secp256k1 curve private key into a DiodeClient.Wallet.t().
This function converts a DiodeClient.Wallet.t() into a binary representation of the public ICP Principal identifier.
https://internetcomputer.org/docs/current/references/ic-interface-spec#id-classes
This function signs a binary with a DiodeClient.Wallet.t() using the secp256k1 algorithm and the ICP signing scheme.
This function converts a DiodeClient.Wallet.t() into a textual representation of the public ICP Principal identifier.