Accessing the exchange rate on the IC, Locally

Hi,

I was wondering if anyone knew how to use NNS locally to access the IC exchange rate to be used for a project?

Thanks.

Do you mean the ICPXDR exchange rate? You can get that from the NNS canister call get_icp_to_cycles_conversion_rate() which returns the current ICPXDR rate (which is used to calculate how many cycles will be generated per ICP).

We use this with StoicWallet, when you are topping up canisters you can view the exact rate (currently ~31T cycles per ICP).

3 Likes

Yes for the ICPXDR exchange rate. How do I access a NNS canister call? Do I need to download anything or can I just code it into Motoko in a price oracle canister? Thanks for your help.

From motoko, you can call the actor function. Requires some work, but it’s not too hard you can get all the info from the docs. I can post an example later when I’m free

That would be great, thank you!

Anyone know where the off-chain price oracle is hosted? AWS? Server in Dfinity’s basement?

I believe the deterministic xdr_per_ipc is on chain.

Get_value(xdr_per_ipc).

this is protobuf; not candid.

1 Like

Something like (in motoko):

type NNSActor = actor { get_icp_to_cycles_conversion_rate : () -> (nat64) };

let nns: NNSActor = actor("qoctq-giaaa-aaaaa-aaaea-cai");
let icpxdr : Nat64 = await nns.get_icp_to_cycles_conversion_rate();
3 Likes

So there’d be two canisters needed, one for NNS and one for the price oracle?
qoctq-giaaa-aaaaa-aaaea-cai would be the canister ID for the NNS?

The example I pasted above should do what you want on its own without a second canister

1 Like

Your question in discussed in this thread (to which I provided an answer):

These oracles are run on multiple independent data centers (neither on AWS nor in DFINITY’s basement). :slightly_smiling_face:

1 Like

this is in nns-ui canister, But the source code is not opened.

Ah, totally missed this. Thanks.

Yeah NNS canister, I pulled the candid from IC.rocks for it