Actions

Interacting With Chainlink Contracts: Difference between revisions

From Chainlink Community Wiki

No edit summary
No edit summary
Line 16: Line 16:


----
----
=== ''' How To Format Request Data ''' ===
Formatting the data we want to send in our RPC calls is a bit tricky if you've never done it before.
This page will assist you in learning how to do this as well as provide outside resources to make it a bit easier.


=== '''EACAggregatorProxy''' ===
=== '''EACAggregatorProxy''' ===
Line 45: Line 51:
blah
blah
----
----
=== '''Convenient Tools''' ===
When we make the requests to the contracts, we have to convert various values into different formats.  For example converting the desired round ID to a uint80.
To assist in accomplishing this, there are a couple online tools that we can utilize.
==== '''Converting Request Types to Hex''' ====
We will need to convert each of the request types to their 4 bit (eight character) hex value
To do this, simply navitgate to [https://emn178.github.io/online-tools/keccak_256.html emn178.github.io/online-tools/keccak_256.html] and copy the desired request into the top box and copy the first 8 characters in the bottom box.
We will want to append a leading <code>0x</code> in front of the request data.
'''Example below:'''
Let's say we want to query <code>getAnswer</code> for round number <code>92233720368547771539</code>.
[[File:GetAnswerExample.png|frameless]]
We'd need to convert <code>getAnswer(uint256)</code> to the first 4 bytes of its hex value, which is <code>b5ab58dc</code>, and then with a leading <code>0x</code>, it would be <code>0xb5ab58dc</code>.
[[File:ConvertRequestToHex.png|frameless|658x658px]]
For some requests, we'll also need to include specific data in our read/write request to the contract.
In that case, we would need to convert that data to the expected format before sending.
==== '''Convert Request Data To Different Types''' ====
Maintaining the above example, we will need to include the desired round number to get the on-chain response from the Chainlink Nodes.
We can make use of the tooling available at [https://adibas03.github.io/online-ethereum-abi-encoder-decoder/#/encode adibas03.github.io/online-ethereum-abi-encoder-decoder/#/encode] to convert our data to any of the expected types.
In this example, we will need to convert our desired round number, <code>92233720368547771514</code>, to a uint256.
the uint256 equivalant of <code>92233720368547771514</code> is <code>000000000000000000000000000000000000000000000005000000000000347a</code>
[[File:ConvertRequestDataToHex.png|frameless|549x549px]]
==== '''Formatting the Request Data''' ====
Now that we have the necessary data to include in our request, we need to combine it into a single hex value.
To accomplish this, we start with the desired call name, in this case <code>0xb5ab58dc</code> .
Then we append the round ID we converted, <code>000000000000000000000000000000000000000000000005000000000000347a</code>, to the end of it.
Resulting in the request data below:
<code>0xb5ab58dc000000000000000000000000000000000000000000000005000000000000347a</code>

Revision as of 17:43, 25 May 2022

How to Query Chainlink Contracts

This page will provide you with information regarding how to query a Chainlink Aggregator

Included are some examples using bash.

All examples are based on the LINK / USD price feed on Ethereum Mainnet


Overview

Each Chainlink Aggregator has a wide range of data that you can query.

From historic price data to the timestamp of the most recent completed round, a lot of information is stored on-chain and available for you to query.

This page will be broken out into each major contract type, and then each individual query that can be made, with examples.


How To Format Request Data

Formatting the data we want to send in our RPC calls is a bit tricky if you've never done it before.

This page will assist you in learning how to do this as well as provide outside resources to make it a bit easier.


EACAggregatorProxy

LINK / USD EACAggregatorProxy contract address: 0x2c1d072e956affc0d435cb7ac38ef18d24d9127c

The Access Controlled Aggregator Proxy is a proxy contract that enables the owner to point it to other contracts as needed/desired.

This prevents the users from having to update anything if they wanted to move to a new contract version/release

Read Calls

The Read calls are queries you can make to each EACAggregatorProxy to get a wide range of data from the proxy's associated AccessControlledOffchainAggregator contract. One such example is to get the latest round data from a price feed.

Write Calls

The Write calls that are available to each EACAggregatorProxy are used to make changes to the contract. An example of a write call would be to change the associated AccessControlledOffchainAggregator


AccessControlledOffchainAggregator

LINK / USD AccessControlledOffchainAggregator contract address: 0xDfd03BfC3465107Ce570a0397b247F546a42D0fA

The Access Controlled Offchain Aggregator is the aggregator contract that the Chainlink Nodes report to.

This is the contract that contains the on-chain information that is read by the EACAggregatorProxy

Read Calls

blah

Write Calls

blah