I’m currently working on a project and would like to integrate the XRC (Exchange Rate Canister) to fetch the ICP-USD exchange rate. I noticed that the XRC demo is implemented in Motoko, but I’m looking for guidance or resources on how to achieve this in Rust.
also i noticed a mock canister inside xrc canister repo but i did not find for how to use it so could anyone share insights on setting up an XRC-like service specifically for Rust? Any example code or steps would be greatly appreciated. @THLO
Thanks in advance!
If you want to run your own instance of the XRC alongside your canister, you can pull it into your project using dfx deps.
Note that the XRC is meant to be run in a system subnet, so you need to configure your local replica accordingly.
For testing on mainnet, I’d recommend sending requests to the main XRC.
It doesn’t matter if your canister is written in Rust or Motoko. In both cases you’ll make the same request to the get_exchange_rate endpoint.
it always gives me error like this Running dfx start for version 0.20.1
Using project-specific network ‘local’ defined in /mnt/d/Mercatura/ICP/Mercx/dfx.json
thread ‘main’ panicked at rs/crypto/internal/crypto_service_provider/src/secret_key_store/proto_store.rs:120:14:
wrong crypto root permissions: “Crypto state directory /mnt/d/Mercatura/ICP/Mercx/.dfx/network/local/state/replicated_state/node-100/crypto has permissions 0o40777, allowing general access”
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
N.B i am a windows system
The XRC charges a small fee for the service it provides. It costs 1B cycles per request. ic_cdk::api::call::call attaches no cycles to the call. You should use call_with_payment128 instead and attach 1B cycles to the call.
The replica is not built to run on Windows and doesn’t even run properly on WSL2. If you want to run it locally, use a dev container.