Skip to content

Latest commit

 

History

History
102 lines (66 loc) · 3.46 KB

README.md

File metadata and controls

102 lines (66 loc) · 3.46 KB

Data Feed Consumer

Consumer smart contract that reads from Orakl Network Data Feed.

Warning: This repository and smart contract are meant to be for deployment on Baobab.

Currently, you can access the following data feeds from Orakl Network.

Contract Addresses

Reference following link to check deployed addresses

Feeds

Others

Prerequisites

Create a copy of .env.example file and fill in values for PROVIDER, and MNEMONIC or PRIV_KEY (the difference is explained below) environment variables. These variables will be used for connection to JSON-RPC endpoint, deployment and use of your DataFeedConsumer smart contract.

cp .env.example .env

PROVIDER can be set to any JSON-RPC endpoint. The list of free available JSON-RPC endpoint can be found in official Klaytn documentation.

This repository supports connection to wallet either through mnemonic or private key.

Mnemonic

MNEMONIC can be generated using npm mnemonics package.

npx mnemonics

After mnemonic is generated, you need to convert it to public address and fund it with KLAY. If you do not have any KLAY in your account, you cannot deploy smart contracts or make any transactions.

You can convert your newly generated mnemonic with following hardhat task. Please replace the [MENONIC] with your mnemonic.

npx hardhat address --mnemonic [MNEMONIC]

The script will print out a public address corresponding to your mnemonic. Then, you can use this address to receive free KLAY using Baobab's faucet.

Private key

If you already have a wallet, you can reuse its private key, and connect to JSON-RPC endpoint with it. In case you use Metamask, read how to export an account's private key.. After you extract private key, store it in PRIV_KEY variable inside of .env file.

Installation

yarn install

Compilation

yarn compile

Deploy

# feed example
npx hardhat deploy --network baobab --deploy-scripts deploy/DataFeedConsumer
# router example
npx hardhat deploy --network baobab --deploy-scripts deploy/DataFeedRouterConsumer

Request the latest value from Data Feed

Before running the script below, one must deploy DataFeedConsumer smart contract. This step has to be performed only once. To deploy DataFeedConsumer, run npx hardhat deploy --network baobab.

Reading information from feed is free of charge for public data feeds. You pay only for deployment of smart contract and execution of its functions.

npx hardhat run scripts/read-data.ts --network baobab

Request the latest value from Data Feed through RouterContract

Pair name's fixed with "BTC-USDT", try out getting latest value of different pairs by changing pair name from the script.

npx hardhat run scripts/read-data-through-router.ts --network baobab