Actions

Interacting With Chainlink Contracts: Difference between revisions

From Chainlink Community Wiki

No edit summary
No edit summary
 
(34 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== '''How to Query Chainlink Contracts''' ==
 
----
 
=== '''How to Query Chainlink Contracts''' ===
This page will provide you with information regarding how to query a Chainlink Aggregator
This page will provide you with information regarding how to query a Chainlink Aggregator


Line 17: Line 20:
----
----


=== '''EACAggregatorProxy''' ===
=== '''How To Format Request Data ''' ===
'''LINK / USD EAC AggregatorProxy contract address: [https://etherscan.io/address/0x2c1d072e956affc0d435cb7ac38ef18d24d9127c#readContract 0x2c1d072e956affc0d435cb7ac38ef18d24d9127c]'''
Formatting the data we want to send in our RPC calls is a bit tricky if you've never done it before.


The Access Controlled Aggregator Proxy is a proxy contract that enables the owner to point it to other contracts as needed/desired.
This page will assist you in learning how to do this as well as provide outside resources to make it a bit easier.


This prevents the users from having to update anything if they wanted to move to a new contract version/release
=== [[Formatting RPC Call Data|'''Formatting RPC Call Data''']] ===
----In the Below tables, you can navigate to pages specific to deploying, verifying, and managing/updating each of the contracts.


Additionally, there are also pages specific to the various read and write calls for each contract with bash+curl examples.
''While curl is nowhere near the most common way to interact with smartcontracts, I felt it would provide the necessary information in the most basic manner.''
----
{| class="wikitable"
! colspan="2" |
=== '''<big>Operator.sol</big>''' ===
|-
| colspan="2" |'''<big>Example Operator contract address:</big>'''
|-
|
==== '''Deploying an Operator''' ====
|Directions on deploying an <code>Operator.sol</code> contract to enable your Chainlink Node to perform Direct Request jobs
|-
|
==== '''Verifying an Operator''' ====
|Directions on how to verify a deployed <code>Operator</code> contract in etherescan
|-
|
==== '''Managing an Operator''' ====
|Directions on managing and updating a deployed <code>Operator</code> contract
|-
|
==== '''Read Calls''' ====
==== '''Read Calls''' ====
|The Read calls are queries you can make to each <code>Operator</code> to get a bit of information from the contract.
|-
|
==== '''Write Calls''' ====
|The Write calls available to each <code>Operator</code> that are used to make changes to the contract.  An example of a write call would be to change the associated the associated Chainlink Node(s)
|}
----
----
 
{| class="wikitable"
===== '''accessController''' =====
! colspan="2" |
The <code>accessController</code> is a smart contract that acts as a whitelist for which addresses are able to call the contract.  For the LINK / USD price feed, the referenced <code>accessController</code> smart contract is a null value set to <code>0x0000000000000000000000000000000000000000</code>
=== '''<big>ATestnetConsumer.sol</big>''' ===
 
|-
* Example Query:
| colspan="2" |'''<big>Example ATestnetConsumer contract address:</big>'''
** <code>ACCESS_CONTROLLER=$(curl -s -H "Content-Type: application/json" https://'''$YOUR_RPC_ENDPOINT''' -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_call", "params":[{"from":null,"to":"0x2c1d072e956AFFC0D435Cb7AC38EF18d24d9127c","data":"0xbc43cbaf"}, "latest"]}' | jq -r .result) && echo "$ACCESS_CONTROLLER"</code>
|-
 
|
* Example Response:
==== '''Deploying a Testnet Consumer''' ====
** <code>0x0000000000000000000000000000000000000000000000000000000000000000</code>
|Directions on deploying an <code>AtestnetConsumer.sol</code> contract to enable your Chainlink Node to perform Direct Request jobs
***(remove leading 24 <code>0</code>'s)
|-
|
==== '''Verifying an Testnet Consumer''' ====
|Directions on how to verify a deployed <code>ATestnetConsumer</code> contract in etherescan
|-
|
==== '''Managing an Testnet Consumer''' ====
|Directions on managing and updating a deployed <code>ATestnetConsumer</code> contract
|-
|
==== '''Read Calls''' ====
|The Read calls are queries you can make to each <code>ATestnetConsumer</code> to get a bit of information from the contract.
|-
|
==== '''Write Calls''' ====
|The Write calls available to each <code>ATestnetConsumer</code> that are used to send test requests to Chainlink Node(s)
|}
----
----
{| class="wikitable"
! colspan="2" |
=== '''<big>AccessControlledAggregator.sol</big>''' ===
|-
| colspan="2" |'''ETH / USD AccessControlledAggregator contract address: [https://etherscan.io/address/0x00c7A37B03690fb9f41b5C5AF8131735C7275446 0x00c7A37B03690fb9f41b5C5AF8131735C7275446]'''
|-
|
==== '''[[Flux monitor|Operational Overview of FluxMonitor Contract]]''' ====
|Details regarding the function of a FluxMonitor contract
|-
|
==== '''[[AccessControlledAggregator Deployment|Deploying a FluxMonitor Contract]]''' ====
|Directions on deploying an <code>AccessControlledAggregator.sol</code> contract.  Also known as FluxMonitor.
|-
|
==== '''[[AccessControlledAggregator Verification|Verifying an FluxMonitor Contract]]''' ====
|Directions on how to verify a deployed <code>AccessControlledAggregator</code> contract in etherescan
|-
|
==== '''[[AccessControlledAggregator Management|Managing an FluxMonitor Contract]]''' ====
|Directions on managing and updating a deployed <code>AccessControlledAggregator</code> contract
|-
|
==== '''[[AccessControlledAggregator Reads|Read Calls]]''' ====
|The Read calls are queries you can make to each <code>AccessControlledAggregator</code> to get a bit of information from the contract.
|-
|
==== '''Write Calls''' ====
|The Write calls available to each <code>AccessControlledAggregator</code> that are used to send test requests to Chainlink Node(s)
|}


===== '''aggregator''' =====
The <code>aggregator</code> is the on-chain contract that each of the Chainlink Nodes responds to.  The <code>AggregatorProxy</code> contract points to the configured Aggregator as it's primary source of information
*Example Query:
** <code>AGGREGATOR=$(curl -s -H "Content-Type: application/json" https://'''$YOUR_RPC_ENDPOINT''' -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_call", "params":[{"from":null,"to":"0x2c1d072e956AFFC0D435Cb7AC38EF18d24d9127c","data":"0x245a7bfc"}, "latest"]}' | jq -r .result) && echo "$AGGREGATOR"</code>


* Example Response:
** <code>0x000000000000000000000000dfd03bfc3465107ce570a0397b247f546a42d0fa</code>
***(remove leading 24 <code>0</code>'s)
----
----
 
{| class="wikitable"
===== '''decimals''' =====
|+
The <code>decimals</code> value tells the reader of the contract how many decimal places they need to adjust to get the proper value.
! colspan="2" |
 
=== '''<big>EACAggregatorProxy.sol</big>''' ===
For example, if the <code>LINK / USD</code> price feed has a decimlas value of <code>8</code>, and the latest round shows a response of <code>726792272</code>, then we would shift the decimal 8 places to end with a value of <code>7.26792272</code>.
|-
 
| colspan="2" |'''LINK / USD EACAggregatorProxy contract address: [https://etherscan.io/address/0x2c1d072e956affc0d435cb7ac38ef18d24d9127c#readContract 0x2c1d072e956affc0d435cb7ac38ef18d24d9127c]'''
* Example Query:
|-
** <code>DECIMALS=$(curl -s -H "Content-Type: application/json" https://'''$YOUR_RPC_ENDPOINT''' -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_call", "params":[{"from":null,"to":"0x2c1d072e956AFFC0D435Cb7AC38EF18d24d9127c","data":"0x313ce567"}, "latest"]}' | jq -r .result) && echo "$((DECIMALS))"</code>
|
* Example Response:
==== '''Deploying an Aggregator Proxy''' ====
** <code>8</code>
|Directions on deploying an <code>EACAggregatorProxy.sol</code> contract to help manage your own price feed
 
|-
|
==== '''Verifying an Aggregator Proxy''' ====
|Directions on how to verify a deployed <code>EACAggregatorProxy</code> contract in etherescan
|-
|
==== '''Managing an Aggregator Proxy''' ====
|Directions on managing and updating a deployed <code>EACAggregatorProxy</code> contract
|-
|
==== '''[[EACAggregatorProxy Reads|Read Calls]]''' ====
|The Read calls are queries you can make to each <code>EACAggregatorProxy</code> to get a wide range of data from the proxy's associated <code>AccessControlledOffchainAggregator</code> contract.  One such example is to get the latest round data from a price feed.
|-
|
==== [[EACAggregatorProxy Writes|'''Write Calls''']] ====
|The Write calls that are available to each <code>EACAggregatorProxy</code> are used to make changes to the contract.  An example of a write call would be to change the associated <code>AccessControlledOffchainAggregator</code>
|}
----
----
 
{| class="wikitable"
===== '''description''' =====
|+
The <code>desctiption</code> of the Proxy is just a friendly name, in this case displaying LINK / USD
{| class="wikitable"
 
! colspan="2" |
* Example Query:
=== '''<big>SimpleWriteAccessController.sol</big>''' ===
** <code>DESCRIPTION=$(curl -s -H "Content-Type: application/json" https://'''$YOUR_RPC_ENDPOINT''' -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_call", "params":[{"from":null,"to":"0x2c1d072e956AFFC0D435Cb7AC38EF18d24d9127c","data":"0x7284e416"}, "latest"]}' | jq -r .result) && echo $DESCRIPTION | xxd -r -p</code>
|-
 
| colspan="2" |'''LINK / USD (Billing) SimpleWriteAccessController contract address: [https://etherscan.io/address/0x9db83cef9f68b63989e4e82d65d549e7ff2acda9#readContract 0x9db83cef9f68b63989e4e82d65d549e7ff2acda9]'''
* Example Response:
|-
** <code>LINK / USD</code>
| colspan="2" |'''LINK / USD (Requester) SimpleWriteAccessController contract address: [https://etherscan.io/address/0x641b698ad1c6e503470520b0eecb472c0589dfe6 0x641b698ad1c6e503470520b0eecb472c0589dfe6]'''
 
|-
|
==== '''[[SimpleWriteAccessController Deployment|Deploying an Access Controller]]''' ====
|Directions on deploying a <code>SimpleWriteAccessController.sol</code> contract to build your own price feed.
|-
|
==== '''[[SimpleWriteAccessController Verification|Verifying an Access Controller]]''' ====
|Directions on how to verify a deployed <code>SimpleWriteAccessController</code> contract in etherscan
|-
|
==== '''Managing an Access Controller''' ====
|Directions on how to manage and update the <code>SimpleWriteAccessController</code> depending on its application
|-
|
==== '''Read Calls''' ====
|The Read calls are queries you can make to each '''<code>SimpleWriteAccessController</code>''' to get relevant information to check access and state of a contract.  One such example is to get to check if a provided address has access permissions to make a specified call.
|-
|
==== '''Write Calls''' ====
|The Write calls that are available to each '''<code>SimpleWriteAccessController</code>''' are used to make changes to the contract.  An example of a write call would be to replace one Chainlink Node for another.
|}
----
----
 
! colspan="2" |
===== '''getAnswer''' =====
=== '''<big>AccessControlledOffchainAggregator.sol</big>''' ===
This call will provide you with the data for the round you have specified.
|-
 
| colspan="2" |'''LINK / USD AccessControlledOffchainAggregator contract address: [https://etherscan.io/address/0xdfd03bfc3465107ce570a0397b247f546a42d0fa#code 0xDfd03BfC3465107Ce570a0397b247F546a42D0fA]'''
|-
|
==== '''[[Offchain reporting|Operational Overview of an OCR Contract]]''' ====
|Details regarding the functionality of an OCR Contract
|-
|
==== '''[[AccessControlledOffchainAggregator Deployment|Deploying an OCR Aggregator]]''' ====
|Directions on deploying an <code>AccessControlledOffchainAggregator.sol</code> contract to build your own price feed.
|-
|
==== '''[[AccessControlledOffchainAggregator Verification|Verifying an OCR Aggregator]]''' ====
|Directions on verifying a deployed <code>AccessControlledOffchainAggregator</code> contract in etherscan
|-
|
==== '''[[AccessControlledOffchainAggregator Management|Managing an OCR Aggregator]]''' ====
|Directions on how to manage and update a deployed OCR Aggregator contract
|-
|
==== '''[[AccessControlledOffchainAggregator Reads|Read Calls]]''' ====
|The Read calls are queries you can make to each '''<code>AccessControlledOffchainAggregator</code>''' to get a wide range of on-chain data.  One such example is to get the latest round data from a price feed.
|-
|
==== '''[[AccessControlledOffchainAggregator Writes|Write Calls]]''' ====
|The Write calls that are available to each '''<code>AccessControlledOffchainAggregator</code>''' are used to make changes to the contract. An example of a write call would be to change the <code>adminAddress</code> of a Chainlink Node
|}
----
----
===== '''getRoundData''' =====
Similar to the above <code>getAnswer</code> call, this call will get additional information from the round you have specified.
----
----
===== '''getTimestamp''' =====
This <code>getTimestamp</code> call will provide you with the timestamp of the block containing the data from the round you have specified.
===== '''latestAnswer''' =====
The <code>latestAnswer</code> call provides you with the value that was written to chain during the most recent completed round
===== '''latestRound''' =====
This call will provide you with the most recent completed round number.
===== '''latestRoundData''' =====
This call is similar to <code>getRoundData</code>, but it will automatically get the round data for the most recently completed round.
===== '''latestTimestamp''' =====
Similar to <code>latestRoundData</code> and <code>getTimestamp</code>, the <code>latestTimestamp</code> call will provide you with the timestamp of the block containing the response from the latest completed round.
===== '''owner''' =====
The owner query will respond with the address that has ownership of the contract you query.
===== '''phaseAggregators''' =====
===== '''phaseId''' =====
===== '''proposedAggregator''' =====
The <code>proposedAggregator</code> query will give you the address of the proposed aggregator, if there is one.
===== '''proposedGetRoundData''' =====
This call provides you with the round data for the requested round from the proposed aggregator, if there is one.
===== '''proposedLatestRoundData''' =====
Similar to the above, this call will get you the data from the latest round of the proposed aggregator.
===== '''version''' =====
This gets you the version of the contract you're querying.

Latest revision as of 19:48, 7 June 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.

Formatting RPC Call Data


In the Below tables, you can navigate to pages specific to deploying, verifying, and managing/updating each of the contracts.

Additionally, there are also pages specific to the various read and write calls for each contract with bash+curl examples.

While curl is nowhere near the most common way to interact with smartcontracts, I felt it would provide the necessary information in the most basic manner.


Operator.sol

Example Operator contract address:

Deploying an Operator

Directions on deploying an Operator.sol contract to enable your Chainlink Node to perform Direct Request jobs

Verifying an Operator

Directions on how to verify a deployed Operator contract in etherescan

Managing an Operator

Directions on managing and updating a deployed Operator contract

Read Calls

The Read calls are queries you can make to each Operator to get a bit of information from the contract.

Write Calls

The Write calls available to each Operator that are used to make changes to the contract. An example of a write call would be to change the associated the associated Chainlink Node(s)

ATestnetConsumer.sol

Example ATestnetConsumer contract address:

Deploying a Testnet Consumer

Directions on deploying an AtestnetConsumer.sol contract to enable your Chainlink Node to perform Direct Request jobs

Verifying an Testnet Consumer

Directions on how to verify a deployed ATestnetConsumer contract in etherescan

Managing an Testnet Consumer

Directions on managing and updating a deployed ATestnetConsumer contract

Read Calls

The Read calls are queries you can make to each ATestnetConsumer to get a bit of information from the contract.

Write Calls

The Write calls available to each ATestnetConsumer that are used to send test requests to Chainlink Node(s)

AccessControlledAggregator.sol

ETH / USD AccessControlledAggregator contract address: 0x00c7A37B03690fb9f41b5C5AF8131735C7275446

Operational Overview of FluxMonitor Contract

Details regarding the function of a FluxMonitor contract

Deploying a FluxMonitor Contract

Directions on deploying an AccessControlledAggregator.sol contract. Also known as FluxMonitor.

Verifying an FluxMonitor Contract

Directions on how to verify a deployed AccessControlledAggregator contract in etherescan

Managing an FluxMonitor Contract

Directions on managing and updating a deployed AccessControlledAggregator contract

Read Calls

The Read calls are queries you can make to each AccessControlledAggregator to get a bit of information from the contract.

Write Calls

The Write calls available to each AccessControlledAggregator that are used to send test requests to Chainlink Node(s)



EACAggregatorProxy.sol

LINK / USD EACAggregatorProxy contract address: 0x2c1d072e956affc0d435cb7ac38ef18d24d9127c

Deploying an Aggregator Proxy

Directions on deploying an EACAggregatorProxy.sol contract to help manage your own price feed

Verifying an Aggregator Proxy

Directions on how to verify a deployed EACAggregatorProxy contract in etherescan

Managing an Aggregator Proxy

Directions on managing and updating a deployed EACAggregatorProxy contract

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

SimpleWriteAccessController.sol

LINK / USD (Billing) SimpleWriteAccessController contract address: 0x9db83cef9f68b63989e4e82d65d549e7ff2acda9
LINK / USD (Requester) SimpleWriteAccessController contract address: 0x641b698ad1c6e503470520b0eecb472c0589dfe6

Deploying an Access Controller

Directions on deploying a SimpleWriteAccessController.sol contract to build your own price feed.

Verifying an Access Controller

Directions on how to verify a deployed SimpleWriteAccessController contract in etherscan

Managing an Access Controller

Directions on how to manage and update the SimpleWriteAccessController depending on its application

Read Calls

The Read calls are queries you can make to each SimpleWriteAccessController to get relevant information to check access and state of a contract. One such example is to get to check if a provided address has access permissions to make a specified call.

Write Calls

The Write calls that are available to each SimpleWriteAccessController are used to make changes to the contract. An example of a write call would be to replace one Chainlink Node for another.

AccessControlledOffchainAggregator.sol

LINK / USD AccessControlledOffchainAggregator contract address: 0xDfd03BfC3465107Ce570a0397b247F546a42D0fA

Operational Overview of an OCR Contract

Details regarding the functionality of an OCR Contract

Deploying an OCR Aggregator

Directions on deploying an AccessControlledOffchainAggregator.sol contract to build your own price feed.

Verifying an OCR Aggregator

Directions on verifying a deployed AccessControlledOffchainAggregator contract in etherscan

Managing an OCR Aggregator

Directions on how to manage and update a deployed OCR Aggregator contract

Read Calls

The Read calls are queries you can make to each AccessControlledOffchainAggregator to get a wide range of on-chain data. One such example is to get the latest round data from a price feed.

Write Calls

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