跳至主要内容

How to Set Up Tellor as your Oracle

soliditysmart contractsoracles
Beginner
Tellor
Tellor Docs(opens in a new tab)
2021年6月29日
2 minute read minute read

Pop Quiz: Your protocol is just about finished, but it needs an oracle to get access to off chain data...What do you do?

(Soft) Prerequisites

This post aims to make accessing an oracle feed as simple and straightforward as possible. That said, we're assuming the following about your coding skill-level to focus on the oracle aspect.

Assumptions:

  • you can navigate a terminal
  • you have npm installed
  • you know how to use npm to manage dependencies

Tellor is a live and open-sourced oracle ready for implementation. This beginner's guide is here to showcase the ease with which one can get up and running with Tellor, providing your project with a fully decentralized and censorship-resistant oracle.

Overview

Tellor is an oracle system where parties can request the value of an offchain data point (e.g. BTC/USD) and reporters compete to add this value to an onchain data-bank, accessible by all Ethereum smart contracts. The inputs to this data-bank are secured by a network of staked reporters. Tellor utilizes crypto-economic incentive mechanisms, rewarding honest data submissions by reporters and punishing bad actors through the issuance of Tellor’s token, Tributes (TRB), and a dispute mechanism.

In this tutorial we'll go over:

  • Setting up the initial toolkit you'll need to get up and running.
  • Walk through a simple example.
  • List out testnet addresses of networks you currently can test Tellor on.

UsingTellor

The first thing you'll want to do is install the basic tools necessary for using Tellor as your oracle. Use this package(opens in a new tab) to install the Tellor User Contracts:

npm install usingtellor

Once installed this will allow your contracts to inherit the functions from the contract 'UsingTellor'.

Great! Now that you've got the tools ready, let's go through a simple exercise where we retrieve the bitcoin price:

BTC/USD Example

Inherit the UsingTellor contract, passing the Tellor address as a constructor argument:

Here's an example:

1import "usingtellor/contracts/UsingTellor.sol";
2
3contract PriceContract is UsingTellor {
4 uint256 public btcPrice;
5
6 //This Contract now has access to all functions in UsingTellor
7
8constructor(address payable _tellorAddress) UsingTellor(_tellorAddress) public {}
9
10function setBtcPrice() public {
11 bytes memory _b = abi.encode("SpotPrice",abi.encode("btc","usd"));
12 bytes32 _queryId = keccak256(_b);
13
14 uint256 _timestamp;
15 bytes _value;
16
17 (_value, _timestamp) = getDataBefore(_queryId, block.timestamp - 15 minutes);
18
19 btcPrice = abi.decode(_value,(uint256));
20 }
21}
顯示全部
複製

For a complete list of contract addresses refer here(opens in a new tab).

For ease of use, the UsingTellor repo comes with a version of the Tellor Playground(opens in a new tab) contract for easier integration. See here(opens in a new tab) for a list of helpful functions.

For a more robust implementation of the Tellor oracle, check out the full list of available functions here(opens in a new tab).

最後編輯: @nhsz(opens in a new tab), 2023年8月15日

這個使用教學對你有幫助嗎?

網站上次更新: 2024年7月24日

學習

  • 學習中心
  • 什麼是以太坊?
  • 什麼是以太幣 (ETH)?
  • 以太坊錢包
  • 什麼是 Web3?
  • 智慧型合約
  • Gas fees
  • 執行節點
  • 以太坊安全及詐騙預防
  • 測驗中心
  • 以太坊詞彙表
(opens in a new tab)(opens in a new tab)(opens in a new tab)
  • 關於我們
  • 以太坊品牌資產
  • 行為守則
  • 工作機會
  • 隱私條款
  • 使用條款
  • Cookie 政策
  • 媒體聯絡方式(opens in a new tab)