# XRC Mock Canister

**URL:** <https://forum.dfinity.org/t/xrc-mock-canister/36998>\
**Category:** Developers\
**Created:** [November 7, 2024, 10:22am UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998 "2024-11-07T10:22:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nourAhmed123](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nourahmed123/32/20737_2.png) [@nourAhmed123](https://forum.dfinity.org/u/nourAhmed123)\
**Post date:** [November 7, 2024, 10:22am UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/1 "2024-11-07T10:22:25Z")

</div>

Hello everyone,

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!

---

<div class="post-metadata">

**Author:** ![THLO](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/thlo/32/2349_2.png) [@THLO](https://forum.dfinity.org/u/THLO)\
**Post date:** [November 7, 2024, 1:05pm UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/2 "2024-11-07T13:05:45Z")

</div>

If you want to run your own instance of the XRC alongside your canister, you can [pull it into your project](https://internetcomputer.org/docs/current/tutorials/developer-journey/level-2/2.3-third-party-canisters#pulling-third-party-canister-dependencies) 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](https://github.com/THLO/xrc_demo/blob/26ff6ae1dfe0ed20db515e96cc7c24ecec5164d8/dfx.json#L27).  
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](https://github.com/dfinity/exchange-rate-canister/blob/6dc4a6eb450bc477d6ea09597c992a3ef31d0d88/src/xrc/xrc.did#L82) endpoint.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![nourAhmed123](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nourahmed123/32/20737_2.png) [@nourAhmed123](https://forum.dfinity.org/u/nourAhmed123)\
**Post date:** [November 10, 2024, 11:42am UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/3 "2024-11-10T11:42:15Z")

</div>

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/a/5/a548de0fcf20030242d25186963fde2a7ed151d5.png)  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/e/0/e0a34eec2b9295d493b22d182ff38158b2bc4e1c.png)

const XRC\_CANISTER\_ID: &str = “avqkn-guaaa-aaaaa-qaaea-cai”;

#[update]  
async fn get\_exchange\_rate(symbol: String) → Result\<ExchangeRate, String\> {  
let request = GetExchangeRateRequest {  
base\_asset: Asset {  
symbol: symbol.clone(),  
class: AssetClass::Cryptocurrency,  
},  
quote\_asset: Asset {  
symbol: “USDT”.to\_string(),  
class: AssetClass::Cryptocurrency,  
},  
timestamp: None,  
};

```
let xrc_canister: Principal = Principal::from_text(XRC_CANISTER_ID).expect("Invalid principal");
let (result,): (GetExchangeRateResult,) = ic_cdk::api::call::call(xrc_canister, "get_exchange_rate", (request,))
    .await
    .map_err(|e| format!("Call failed: {:?}", e))?;

match result {
    GetExchangeRateResult::Ok(rate) => Ok(rate),
    GetExchangeRateResult::Err(err) => Err(format!("Error getting exchange rate: {:?}", err)),
}

```

} This what i did and i recieve the same error always not enough cycles , is what i implemented is a correct way ?

---

<div class="post-metadata">

**Author:** ![THLO](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/thlo/32/2349_2.png) [@THLO](https://forum.dfinity.org/u/THLO)\
**Post date:** [November 11, 2024, 12:42pm UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/4 "2024-11-11T12:42:23Z")

</div>

> [@nourAhmed123](#):
>
> always not enough cycles

Did you set the subnet type to “system” as I wrote above?

---

<div class="post-metadata">

**Author:** ![nourAhmed123](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nourahmed123/32/20737_2.png) [@nourAhmed123](https://forum.dfinity.org/u/nourAhmed123)\
**Post date:** [November 11, 2024, 1:32pm UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/5 "2024-11-11T13:32:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [November 12, 2024, 10:28am UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/6 "2024-11-12T10:28:47Z")

</div>

> [@nourAhmed123](#):
>
> would like to integrate the XRC (Exchange Rate Canister) to fetch the ICP-USD exchange rate

You don’t need to create your own XRC canister to get the ICP-USD rate. Just making sure you know that.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [November 12, 2024, 12:44pm UTC](https://forum.dfinity.org/t/xrc-mock-canister/36998/7 "2024-11-12T12:44:35Z")

</div>

> [@nourAhmed123](#):
>
> ```auto
> let (result,): (GetExchangeRateResult,) = ic_cdk::api::call::call(xrc_canister, "get_exchange_rate", (request,))
> .await
> .map_err(|e| format!("Call failed: {:?}", e))?;
> 
> ```

The XRC charges a small fee for the service it provides. It costs [1B cycles per request](https://internetcomputer.org/docs/current/developer-docs/defi/exchange-rate-canister/#cycles-cost). `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.

> [@nourAhmed123](#):
>
> N.B i am a windows system

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.
