Skip to content

Commit 99c0001

Browse files
committed
updated chronicle and chainlink oracle guides
1 parent 57840d1 commit 99c0001

File tree

11 files changed

+8
-884
lines changed

11 files changed

+8
-884
lines changed

docs/tools/oracles/api3.md

Lines changed: 0 additions & 394 deletions
This file was deleted.

docs/tools/oracles/chainlink.md

Lines changed: 6 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88

99
One of Chainlink's most powerful features is already decentralized, aggregated, and ready to be digested on-chain data on most of the popular cryptocurrencies. These are known as [**Chainlink Data Feeds**](https://docs.chain.link/docs/using-chainlink-reference-contracts).
1010

11-
Here is a working example of a contract that pulls the latest price of MATIC in USD on the Mumbai Testnet.
11+
Here is a working example of a contract that pulls the latest price of POL in USD on the Amoy Testnet.
1212

1313
All you need to do is swap out the address [with any address of a data feed](https://docs.chain.link/docs/matic-addresses#config) that you wish, and you can start digesting price information.
1414

1515
```solidity
16-
pragma solidity ^0.6.7;
16+
pragma solidity ^0.8.26;
1717
1818
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
1919
2020
contract PriceConsumerV3 {
2121
AggregatorV3Interface internal priceFeed;
2222
2323
/**
24-
* Network: Mumbai Testnet
25-
* Aggregator: MATIC/USD
26-
* Address: 0xd0D5e3DB44DE05E9F294BB0a3bEEaF030DE24Ada
24+
* Network: Amoy Testnet
25+
* Aggregator: POL/USD
26+
* Address: 0x001382149eBa3441043c1c66972b4772963f5D43
2727
*/
2828
constructor() public {
29-
priceFeed = AggregatorV3Interface(0xd0D5e3DB44DE05E9F294BB0a3bEEaF030DE24Ada);
29+
priceFeed = AggregatorV3Interface(0x001382149eBa3441043c1c66972b4772963f5D43);
3030
}
3131
3232
/**
@@ -44,181 +44,3 @@ contract PriceConsumerV3 {
4444
}
4545
}
4646
```
47-
48-
## Request and receive cycle
49-
50-
Chainlink's Request and Receive cycle enables your smart contracts to make a request to any external API and consume the response. To implement it, your contract needs to define two functions:
51-
52-
1. One to **request the data**, and
53-
2. Another to **receive the response**.
54-
55-
To request data, your contract builds a `request` object which it provides to an oracle. Once the oracle has reached out to the API and parsed the response, it will attempt to send the data back to your contract using the callback function defined in your smart contract.
56-
57-
## Uses
58-
59-
1. **Chainlink Data Feeds**
60-
61-
These are decentralized data reference points already aggregated on-chain, and the quickest, easiest, and cheapest way to get data from the real world. Currently supports some of the most popular cryptocurrency and fiat pairs.
62-
63-
For working with Data Feeds, use the [**Polygon Data Feeds**](https://docs.chain.link/data-feeds/price-feeds/addresses/?network=polygon) from the Chainlink documentation.
64-
65-
2. **Chainlink Verifiable Randomness Function**
66-
67-
Get provably random numbers, where the random number is cryptographically guaranteed to be random.
68-
69-
For working with Chainlink VRF, use the [**Polygon VRF**](https://docs.chain.link/vrf/v2/subscription/supported-networks) addresses from the [Chainlink documentation](https://docs.chain.link/vrf/v2/subscription/examples/get-a-random-number).
70-
71-
3. **Chainlink API Calls**
72-
73-
How to configure your smart contract to work with traditional APIs, and customize to get any data, send any requests over the internet, and more.
74-
75-
## Code example
76-
77-
To interact with external APIs, your smart contract should inherit from [`ChainlinkClient.sol`](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.6/ChainlinkClient.sol), which is a contract designed to make processing requests easy. It exposes a struct called `Chainlink.Request`, which your contract should use to build the API request.
78-
79-
The request should define the oracle address, job id, fee, adapter parameters, and the callback function signature. In this example, the request is built in the `requestEthereumPrice` function.
80-
81-
`fulfill` is defined as the callback function.
82-
83-
```solidity
84-
pragma solidity ^0.6.0;
85-
86-
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
87-
88-
contract APIConsumer is ChainlinkClient {
89-
90-
uint256 public price;
91-
92-
address private oracle;
93-
bytes32 private jobId;
94-
uint256 private fee;
95-
96-
/**
97-
* Network: Polygon Mumbai Testnet
98-
* Oracle: 0x58bbdbfb6fca3129b91f0dbe372098123b38b5e9
99-
* Job ID: da20aae0e4c843f6949e5cb3f7cfe8c4
100-
* LINK address: 0x326C977E6efc84E512bB9C30f76E30c160eD06FB
101-
* Fee: 0.01 LINK
102-
*/
103-
constructor() public {
104-
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
105-
oracle = 0x58bbdbfb6fca3129b91f0dbe372098123b38b5e9;
106-
jobId = "da20aae0e4c843f6949e5cb3f7cfe8c4";
107-
fee = 10 ** 16; // 0.01 LINK
108-
}
109-
110-
/**
111-
* Create a Chainlink request to retrieve API response, find the target price
112-
* data, then multiply by 100 (to remove decimal places from price).
113-
*/
114-
function requestBTCCNYPrice() public returns (bytes32 requestId)
115-
{
116-
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
117-
118-
// Set the URL to perform the GET request on
119-
// NOTE: If this oracle gets more than 5 requests from this job at a time, it will not return.
120-
request.add("get", "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=CNY&apikey=demo");
121-
122-
// Set the path to find the desired data in the API response, where the response format is:
123-
// {
124-
// "Realtime Currency Exchange Rate": {
125-
// "1. From_Currency Code": "BTC",
126-
// "2. From_Currency Name": "Bitcoin",
127-
// "3. To_Currency Code": "CNY",
128-
// "4. To_Currency Name": "Chinese Yuan",
129-
// "5. Exchange Rate": "207838.88814500",
130-
// "6. Last Refreshed": "2021-01-26 11:11:07",
131-
// "7. Time Zone": "UTC",
132-
// "8. Bid Price": "207838.82343000",
133-
// "9. Ask Price": "207838.88814500"
134-
// }
135-
// }
136-
string[] memory path = new string[](2);
137-
path[0] = "Realtime Currency Exchange Rate";
138-
path[1] = "5. Exchange Rate";
139-
request.addStringArray("path", path);
140-
141-
// Multiply the result by 10000000000 to remove decimals
142-
request.addInt("times", 10000000000);
143-
144-
// Sends the request
145-
return sendChainlinkRequestTo(oracle, request, fee);
146-
}
147-
148-
/**
149-
* Receive the response in the form of uint256
150-
*/
151-
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
152-
{
153-
price = _price;
154-
}
155-
}
156-
```
157-
158-
## Mainnet Polygon LINK token
159-
160-
To get mainnet Polygon LINK token from the Ethereum Mainnet, you must follow a 2-step process.
161-
162-
1. Bridge your LINK using the [PoS bridge](https://wallet.polygon.technology/bridge).
163-
2. Swap the LINK for the ERC677 version via the [Pegswap, deployed by the Chainlink](https://pegswap.chain.link/).
164-
165-
The Polygon bridge brings over an ERC20 version of LINK, and LINK is an ERC677, so we just have to update it with this swap.
166-
167-
## Addresses
168-
169-
There are currently only a few operational Chainlink oracles on the Polygon Mumbai Testnet. You can always run one yourself too, and list it on the Chainlink Marketplace.
170-
171-
* Oracle: [`0xb33D8A4e62236eA91F3a8fD7ab15A95B9B7eEc7D`](https://mumbai.polygonscan.com/address/0x58bbdbfb6fca3129b91f0dbe372098123b38b5e9/transactions)
172-
* LINK: [`0x326C977E6efc84E512bB9C30f76E30c160eD06FB`](https://mumbai.polygonscan.com/address/0x70d1F773A9f81C852087B77F6Ae6d3032B02D2AB/transactions)
173-
174-
To obtain LINK on Mumbai Testnet, head to the [Polygon faucet here](https://faucet.polygon.technology/).
175-
176-
## Supported APIs
177-
178-
Chainlink's Request and Receive cycle is flexible enough to call any public API, so long as the request parameters are correct and the response format is known. For example, if the response object from a URL we want to fetch from is formatted like this: `{"USD":243.33}`, the path is simple: `"USD"`.
179-
180-
If an API responds with a complex JSON object, the **path** parameter would need to specify where to retrieve the desired data, using a dot delimited string for nested objects. For example, consider the following response:
181-
182-
```json
183-
{
184-
"Prices":{
185-
"USD":243.33
186-
}
187-
}
188-
```
189-
190-
This would require the following path: `"Prices.USD"`. If there are spaces in the strings, or the strings are quite long, we can use the syntax shown in the example above, where we pass them all as a string array.
191-
192-
```json
193-
string[] memory path = new string[](2);
194-
path[0] = "Prices";
195-
path[1] = "USD";
196-
request.addStringArray("path", path);
197-
```
198-
199-
## What are job IDs for?
200-
201-
You may have noticed that our [example](#code-example) uses a `jobId` parameter when building the request. Jobs are comprised of a sequence of instructions that an oracle is configured to run. In the [code example](#code-example) above, the contract makes a request to the oracle with the job ID: `da20aae0e4c843f6949e5cb3f7cfe8c4`. This particular job is configured to do the following:
202-
203-
* Make a GET request
204-
* Parse the JSON response
205-
* Multiply the value by *x*
206-
* Convert the value to `uint`
207-
* Submit to the chain
208-
209-
This is why our contract adds in the URL, the path of where to find the desired data in the JSON response, and the times amount to the request; using the `request.add` statements. These instructions are facilitated by what's known as Adapters, in the oracle.
210-
211-
**Every request to an oracle must include a specific job ID.**
212-
213-
Here is the list of jobs that the Polygon oracle is configured to run.
214-
215-
| Name | Return Type | ID | Adapters |
216-
|-----|--------|------|-------|
217-
| HTTP GET | `uint256` | `da20aae0e4c843f6949e5cb3f7cfe8c4` | `httpget`<br/>`jsonparse`<br/>`multiply`<br/>`ethuint256`<br/>`ethtx` |
218-
| HTTP GET | `int256` | `e0c76e45462f4e429ba32c114bfbf5ac` | `httpget`<br/>`jsonparse`<br/>`multiply`<br/>`ethint256`<br/>`ethtx` |
219-
| HTTP GET | `bool` | `999539ec63414233bdc989d8a8ff10aa` | `httpget`<br/>`jsonparse`<br/>`ethbool`<br/>`ethtx` |
220-
| HTTP GET | `bytes32` | `a82495a8fd5b4cb492b17dc0cc31a4fe` | `httpget`<br/>`jsonparse`<br/>`ethbytes32`<br/>`ethtx` |
221-
| HTTP GET | `string` | `7d80a6386ef543a3abb52817f6707e3b` | `httpget`<br/>`jsonparse`<br/>`ethstring`<br/>`ethtx` |
222-
| HTTP POST | `bytes32` | `a82495a8fd5b4cb492b17dc0cc31a4fe` | `httppost`<br/>`jsonparse`<br/>`ethbytes32`<br/>`ethtx` |
223-
224-
The complete Chainlink API reference can be found [here](https://docs.chain.link/any-api/api-reference).

docs/tools/oracles/diadataoracles.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/tools/oracles/ora.md

Lines changed: 0 additions & 73 deletions
This file was deleted.

docs/tools/oracles/pyth.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

docs/tools/oracles/razor.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)