How to consume data from the Price Feeds

I need to get the ETH/USD price from the feeds:

https://makerdao.com/en/feeds/

I’m trying to read from the ETH oracle contract: https://etherscan.io/address/0x81FE72B5A8d1A857d176C3E7d5Bd2679A9B85763

If I use the peek method, I get 0x08c379a000000000000000000000000000000000000000000000000000000000 back. peek is implemented as:

return (bytes32(uint(cur.val)), cur.has == 1);

cur.val is of type uint128 If I convert back the return value of peek with:

contract Bytes {
  function convert(bytes32 b) public pure returns(uint) {
    return uint(b);
  }
}

I get 3963877391197344453575983046348115674221700746820753546331534351508065746944 back. I can’t make any sense from this data.

Is there a way to read data directly from the contract? What am I doing wrong.

If I use the peek method, I get 0x08c379a000000000000000000000000000000000000000000000000000000000 back.
That doesn’t look right. If anything it looks like a function signature.

The contract you’re looking at is the Oracle Security Module and has whitelisted functions read and peek to obtain the price. You can find the verified code for it on etherscan. You will need to submit MIP10c9 for your contract to get on the whitelist to obtain read access.

2 Likes

Even if I just want to read data I still need permission?

contract uses Oracle data in a permissioned manner so as to prohibit on-chain parasitic behavior by 3rd parties.

What does it mean by parasitic? I either connect to my own node or through some provider like Infura. I already have access to the data anyways. Since reads are not transactions, they are not broadcasted. In the end I’m limited only by the bandwidth of my own node or the limits set by Infura.

If a 3rd party contract want to do it in a permission-less way, then if it’s just reading data, the scenario is the same as above. If it’s reading data from the feed to make a transactions, the call will be included in the gas costs of the transaction.

So how exactly this “parasitic” behavior would occur?

Am I missing something?

In the end, I can still peek into the events generated by the contract and they have the information I need (e.g.: LogValue). I just need to get the latest one, which would essentially be the current value returned by peek AFAIK. I know that events are not stored on-chain, only their bloom filters, but they are still living in the archive nodes.

I don’t have a contract. My intention was to consume this directly from a frontend application. I know there are centralized APIs that provide USD/ETH prices, but the whole idea is not to depend upon centralized 3rd parties.

My team used to read from Etherscan API, but looks like they recently changed something in their server and now they don’t allow CORS, which broke some of our apps.

The data is only permissioned when it comes to on-chain access so Maker Governance can monetize the Oracles service. The use of the parasitic behavior terminology comes from a whitelisted entity leaking the data to non-whitelisted entities.

For off-chain you have a multitude of options none of which require being on the whitelist. One is to query the raw storage slot containing the data. The other as you noted is to observe the LogValue events.