Create your Chainlink oracle on Ethereum

In the previous article, I created a guide for installing your Chainlink node, use it if you don’t have a running node, as this is required for oracle deployment.

The next step will be to deploy the oracle contract and link it to the node.

The oracle contract is the on-chain component for the oracle service: it listens for data requests from other contracts, relays data queries to oracle nodes, and broadcasts returned data to client contracts. This contract may also perform some computation on the returned data points to produce an aggregate value that it sends to the requesting contract.

We need to deploy one of the contracts like Oracle.sol or Operator.sol on the blockchain.

Oracle.sol is an old type of contract that does not support “large responses” and hence won’t support multi-word responses. Operator.sol is a new type that supports large responses but consumes more gas.

Choose the type of contract based on your task: if you need to get a short response with a single variable, then select — Oracle.sol, and if you need to return several values to the contract — Operator.sol.

I’ll show you an example of how to configure both options. Let’s start with Oracle.sol.

To deploy the contract, we will use Remix, yes, you can also use tools such as Hardhat or Truffle, but in the guide, I will look at the example of Remix.

To deploy the Oracle.sol contract, copy the following code:

// SPDX-License-Identifier: MIT
pragma solidity 0.6.6;
import "@chainlink/contracts/src/v0.6/Oracle.sol";

Create a new Solidity contract file and paste the contents above into it. You can also go to the compiler settings and enable contract optimization.

Next, go to the deployment tab, and select the desired environment, for example: Injected provider — Metamask. Connect to the account that will be used for deployment and specify the required network.

To deploy it, choose Oracle contract and set the parameter — the address of the contract LINK in the specified network (find it in the Chainlink documentation) and click the transact button.

Next, we need to grant permission to the wallet of our node to record the results of the oracle functions. The node’s wallet address is located in the Chainlink Operator GUI in the upper right corner of the home page. Copy it, call the setFulfillmentPermission Oracle contract function, paste it into the arguments and set the value to true.

That’s it, at this stage you have deployed your oracle, you just need to connect interaction with it to another smart contract.

And what about the Operator.sol contract, how to deploy it?

OK, to do this, copy the following code:

// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
import "@chainlink/contracts/src/v0.7/Operator.sol";

Here we will need to specify the address of the LINK contract and the address of the contract owner who will be able to withdraw LINK tokens (you can also specify the address of the Gnosis safe).

After deploying the contract, as before in the Oracle.sol contract, we need to add the node wallet address. To do this, call the setAuthorizedSenders function and insert the address in the following format into the arguments: [“address”]

You have deployed your oracle contract perfectly, in the next article I will write about how smart contracts can interact with oracle.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store