Tabi Link Oracle
Introduction
Tabi Link includes Oracle and VRF, where Oracle represents an oracle that enables smart contracts to retrieve data from the outside world. VRF, also known as a verifiable random function, is a provably fair and verifiable random number generator (RNG) that enables smart contracts to access random values without affecting security or availability.
I. Oracle
Working principle:
Consumer Address: 0xdD325193a3195b4654b12EaCFE0fE548C7761590
Oracle address: 0x590311669252DCF34bfbF3981747D13Cf09ec19A
Existing jobs are as follows:
Get > Uint256 - (TOML) : 5b507ee5e7af477ebf31d4efaa5ba85b
Get > Int256 - (TOML) : bcb8bc009e6042dd96727b61f4bd0238
Get > Bool - (TOML) : ecacc544321640c399ddec5e99d6197f
Get > String : a109c25f143d4adf9a5258628ad88bb2
Get > Bytes : 264423c8ec534be6af0bb24ec8b1fdfa
multi-word (TOML) : c7116b94377d41cb94b4fe9ea38e1d3a
Consumer contracts are as follows:
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
import {Chainlink, ChainlinkClient} from "./ChainlinkClient.sol";
import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol";
/**
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/
contract ATestnetConsumer is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;
uint256 public currentPrice;
event RequestEthereumPriceFulfilled(
bytes32 indexed requestId,
uint256 indexed price
);
constructor() ConfirmedOwner(msg.sender) { }
function requestEthereumPrice(
address _oracle,
string memory _jobId
) public onlyOwner {
Chainlink.Request memory req = buildChainlinkRequest(
stringToBytes32(_jobId),
address(this),
this.fulfillEthereumPrice.selector
);
req.add(
"get",
"https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD"
);
req.add("path", "USD");
req.addInt("times", 100);
sendChainlinkRequestTo(_oracle, req, 0);
}
function fulfillEthereumPrice(
bytes32 _requestId,
uint256 _price
) public recordChainlinkFulfillment(_requestId) {
emit RequestEthereumPriceFulfilled(_requestId, _price);
currentPrice = _price;
}
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))
}
}
}Request code:
The results are as follows:
Detailed code can be found in tabi-oracle\
II. VRF
The specific process is shown in the figure.
VRF Consumer Address: 0xb484B5F803F912C074Ac204dC66114F06aBc2100
VRF Coordinator Address: 0x9492b270EdA7d4046D6aa5e3F15c24deD2c8BD25
The contract code for VRFConsumer.sol is as follows:
VRFConsumerBase.sol contract:
The request code is as follows:
See VRF Example
Last updated