Skip to content

Commit 9238a66

Browse files
klayoracleincgitbook-bot
authored andcommitted
GITBOOK-24: change request with no subject merged in GitBook
1 parent c25cfa6 commit 9238a66

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed

SUMMARY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
* [Node & data provider communication](fundamentals/node-and-data-provider-communication.md)
1111
* [Installing KlayOracle](fundamentals/installing-klayoracle.md)
1212

13+
## Smart Contract Developers
14+
15+
* [Price Feeds](smart-contract-developers/price-feeds/README.md)
16+
* [Quick Start: Code Samples](smart-contract-developers/price-feeds/quick-start-code-samples.md)
17+
* [How to Use KlayOracle Price Feeds](smart-contract-developers/price-feeds/how-to-use-klayoracle-price-feeds.md)
18+
* [Random Number Generator](smart-contract-developers/random-number-generator/README.md)
19+
* [Quick Start: Code Samples](smart-contract-developers/random-number-generator/quick-start-code-samples.md)
20+
* [How to Use KlayOracle Random Number Generator](smart-contract-developers/random-number-generator/how-to-use-klayoracle-random-number-generator.md)
21+
1322
## Data Providers
1423

1524
* [Introduction](data-providers/introduction.md)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Price Feeds
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# How to Use KlayOracle Price Feeds
2+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Quick Start: Code Samples
2+
3+
## Retrieving the KLAY/USD pair price
4+
5+
### Solidity Example
6+
7+
```solidity
8+
// SPDX-License-Identifier: MIT
9+
10+
pragma solidity ^0.8.16;
11+
12+
import "./KlayOracleInterface.sol";
13+
14+
contract OracleConsumerSample {
15+
address public immutable oracleAddress;
16+
17+
uint256 public klayOutput;
18+
19+
constructor(address _oracleAddress) {
20+
require(_oracleAddress != address(0));
21+
oracleAddress = _oracleAddress;
22+
}
23+
24+
function swapEthtoKlay() public returns (bool) {
25+
KlayOracleInterface oracle = KlayOracleInterface(oracleAddress);
26+
27+
bool replied = oracle.newOracleRequest(
28+
this.swap.selector,
29+
address(this)
30+
);
31+
32+
return replied;
33+
}
34+
35+
function swap(uint256 _klayOutput) public {
36+
klayOutput = _klayOutput;
37+
//Swap eth to klay
38+
}
39+
}
40+
```
41+
42+
### JavaScript example
43+
44+
```javascript
45+
const oracleAddress = "0xbc884088e406422a3ef39aedd1c546de7ac4be7c";
46+
47+
const abi = [
48+
{
49+
"inputs": [],
50+
"name": "latestRound",
51+
"outputs": [
52+
{
53+
"internalType": "bytes32",
54+
"name": "answer",
55+
"type": "bytes32"
56+
},
57+
{
58+
"internalType": "uint256",
59+
"name": "roundTime",
60+
"type": "uint256"
61+
},
62+
{
63+
"internalType": "uint256",
64+
"name": "timestamp",
65+
"type": "uint256"
66+
}
67+
],
68+
"stateMutability": "view",
69+
"type": "function"
70+
}
71+
]
72+
73+
const provider = new ethers.providers.JsonRpcProvider("https://api.baobab.klaytn.net:8651");
74+
75+
const oracleContract = new ethers.Contract(oracleAddress, abi, provider);
76+
77+
const [answer, roundTime, timestamp] = await oracleContract.latestRound()
78+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Random Number Generator
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# How to Use KlayOracle Random Number Generator
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Quick Start: Code Samples
2+

0 commit comments

Comments
 (0)