Flux Protocol: How to set up a smart contract as Data Requester?

Saroj Duwadi
3 min readSep 24, 2021

I explained in my earlier medium post about the core mechanism of Flux. One of the core tasks of Flux Protocol is to provide the data to the data requester.

Source: Flux Protocol

To be able to request the data in testnet deployment of Flux on NEAR protocol one should set up the smart contract as a data requester. The prerequisites are that you need to know the command line, crypto wallets, GitHub, and smart contracts.

To set up the contract one should need the rust environment and NEAR CLI

1. Install the Rust toolchain

a. Install Rustup

Run curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

b. Configure your current shell#

Run source $HOME/.cargo/env

c. Add wasm target to your toolchain#

Run rustup target add wasm32-unknown-unknown

2. Create a NEAR account

The best way to create an account on NEAR is using the NEAR Wallet. Let's create one testnet account.

Reserve an Account ID

Source: NEAR

3. Install the near-cli#

npm install -g near-cli

After all this process we have successfully set up everything for the requester contract.

Now, it's time to download the Requester Sample Contract from here. These contracts are used to create and submit data requests to Flux oracle. Download the ZIP version of the requester sample contract.

Login to the NEAR testnet account:

near login

Go to the folder where you just cloned the Requester Sample Contract and follow the following command:

sh build.sh
sh scripts/deploy_requester.sh — accountId YOUR_TESTNET_ACCT_ID.testnet

Once everything is compiled and wasm file has been made we are ready to deploy.

If you run the deploy requeseter script with your account id it will first set up your testnet account with our wrapped NEAR token contract in the oracle contract. It will convert your test net NEAR into wrapped NEAR to be able to use the oracle and it will deploy your request or contract on the near testnet with your account.

Finally, your contract is set up and running on testnet. Now you can start making the data requests.

Example data request arguments:

“{\”amount\”: \”1000000000000000000000000\”,

\”payload\”: {

\”sources\”: [

{\”end_point\”: \”https://api.coingecko.com/api/v3/coins/bitcoin/market_chart/range?vs_currency=usd&from=1629805695&to=1629806000\",

\”source_path\”: \”prices[\$\$last][1]\”}],\”tags\”:[\”pricing\”,\”btc\”],\”challenge_period\”:\”120000000000\”,\”settlement_time\”:\”1\”,\”data_type\”:{\”Number\”:\”10000000000\”},
\”creator\”:\”YOUR_TESTNET_ACCOUNT_ID\”}}”

Run the request script located in the scripts with your testnet id.

sh scripts/request.sh YOUR_TESTNET_ACCOUNT_ID

Congratulations!!!!! you have just made the first request.

You can check the outcome of the request from the following command :

sh scripts/response.sh YOUR_TESTNET_ACCOUNT_ID YOUR_REQUEST_NONCE

If you want to learn more about the setting of data requesters please visit :
https://docs.fluxprotocol.org/docs/getting-started/data-requesters

To know more about the flux protocol:

Website: https://www.fluxprotocol.org/
Twitter: https://twitter.com/fluxprotocol

--

--

Saroj Duwadi

I like to talk about the crypto and web3 ecosystem.