Accessing the exchange rate on the IC, Locally

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();
4 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

Hey everyone!
If you are using the exchange rate in your projects, be aware that the mechanism will change in the upcoming weeks.
Specifically, the exchange rate will no longer be maintained in the NNS registry. Instead, the cycles minting canister will store it directly and make it available using the same interface.

2 Likes

Quick update: The change that I mentioned above is now live.
You can request the exchange rate directly from the cycles minting canister (rkp4c-7iaaa-aaaaa-aaaca-cai).

1 Like

I’m trying to get the XDR-to-ICP exchange rate through the minting canister using the method that previously existed on the registry canister (get_icp_to_cycles_conversion_rate()), but am getting an error that this method doesn’t exist on the minting canister. I wonder if it’s been renamed?

The function is called get_icp_xdr_conversion_rate() as you can see here.
You can test it using dfx:

dfx canister --no-wallet --network ic call --query "rkp4c-7iaaa-aaaaa-aaaca-cai" get_icp_xdr_conversion_rate
2 Likes

Where can we find the .did files for this canister?
ic.rocks doesn’t show it.

1 Like

You can find it here :upside_down_face:: Canlista - NNS Cycles Minting

5 Likes

Thank you, that’s what I was looking for

3 Likes

very helpful @Ori . I just saw this thread.

1 Like

Does anyone know why theres a get_average_icp_xdr ex rate as well?

Right now ICP is 7.07 ish dollars and from google 1 xdr is about 1.334 some dollars. So xdr to icp function is giving me the correct answer of about 5.19ish xdr per icp.

But the avg_xdr to icp exchange rate is giving me 7.6680. I dont know where this is coming from.

That’s the average ICP/XDR rate over the past 30 days. This is used to calculate node provider rewards. You can also see this on the IC dashboard Conversion Rate chart.

2 Likes