Skip to main content

Hello World Example

Biibot Oracle is 100% compatible with Chainlink. If you have any questions, please don't hesitate to reach out to us(Twitter) for help.

Deploy your comsumer contract to Meer network

  1. Open Remix

  2. Create OracleConsumer.sol file in Remix

  3. Copy consumer contract code to OracleConsumer.sol file (The source code is at the bottom of this page)

  4. On the Compiler tab, click the Compile button for OracleConsumer.sol

  5. On the Deploy and Run tab, configure the following settings:

    • Select Injected Provider as your environment. Make sure your metamask is connected to Sepolia.
    • Select OracleConsumer from the Contract menu.
  6. Click Deploy. MetaMask prompts you to confirm the transaction.

  7. Set oracle fee payment token

    image

  8. Set oracle contract address

    image

  9. Set oracle job id

  10. Send funds to your contract

  11. Create a price request

    • Input the Base and quote coin in the form, base coin support: btc eth meer usdt, quote coin support: usdt

    image

  12. After the transaction processes completed, you can get price by click currentPrice function.

    image

Consumer contract code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";

contract OracleConsumer is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;

uint256 private constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18
uint256 public currentPrice;

string public jobId;
address public oracle;

event RequestEthereumPriceFulfilled(
bytes32 indexed requestId,
uint256 indexed price
);


constructor() ConfirmedOwner(msg.sender) {}

function setLinkToken(address _link) public onlyOwner {
_setChainlinkToken(_link);
}

function setOracle(address _oracle) public onlyOwner {
oracle = _oracle;
}

function setJobId(string memory _jobId) public onlyOwner {
jobId = _jobId;
}

function requestPrice(
string memory _base,
string memory _quote
) public onlyOwner {
Chainlink.Request memory req = _buildChainlinkRequest(
stringToBytes32(jobId),
address(this),
this.fulfillEthereumPrice.selector
);
req._add("base", _base);
req._add("quote", _quote);
_sendChainlinkRequestTo(oracle, req, ORACLE_PAYMENT);
}

function requestEthereumPrice(
address _oracle,
string memory _jobId,
string memory _base,
string memory _quote
) public onlyOwner {
Chainlink.Request memory req = _buildChainlinkRequest(
stringToBytes32(_jobId),
address(this),
this.fulfillEthereumPrice.selector
);
req._add("base", _base);
req._add("quote", _quote);
_sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
}

function fulfillEthereumPrice(
bytes32 _requestId,
uint256 _price
) public recordChainlinkFulfillment(_requestId) {
emit RequestEthereumPriceFulfilled(_requestId, _price);
currentPrice = _price;
}

function getChainlinkToken() public view returns (address) {
return _chainlinkTokenAddress();
}

function withdrawLink() public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(_chainlinkTokenAddress());
require(
link.transfer(msg.sender, link.balanceOf(address(this))),
"Unable to transfer"
);
}

function cancelRequest(
bytes32 _requestId,
uint256 _payment,
bytes4 _callbackFunctionId,
uint256 _expiration
) public onlyOwner {
_cancelChainlinkRequest(
_requestId,
_payment,
_callbackFunctionId,
_expiration
);
}

function stringToBytes32(
string memory source
) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}

assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}