Tellor 🛠Reading Tellor Data for Any Use Case - Tally Wiesenberg
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Tally Wiesenberg of Tellor for a workshop titled "Reading Tellor Data for Any Use Case" Welcome to ETHSanFrancisco—our first west-coast hackathon in nearly four years. Experiment with Ethereum in the tech capital of the world and win $300k+ in prizes to take your ideas to the next level. Build with support from 24/7 technical mentors, enjoy delicious food & drinks, and get exclusive access to teams like IPFS/Filecoin, Polygon, Optimism, SKALE, Worldcoin, and more at our biggest IRL event yet! With The Merge now complete, join thousands of developers and creatives rushing into the ecosystem and be part of this moment in web3 history.
Transcript
foreign [Applause] [Music] my name is tally I'm a devoteller the decentralized Oracle and in this tutorial I'm going to walk you through how to read teller data into your own smart contract in this tutorial we're going to create a sample smart contract that reads data from the Rick and Morty API using teller we're going to deploy our contract to rink B and finally we'll tip to teller or in other words will incentivize will pay some trb to incentivize the tele reporters to update our data over time before I get started I will be referencing a lot of links um throughout the course of the tutorial you can see one right here and you can actually find all the links um in the description and as well I'll be linking them in the in the code here and finally in the description of or the readme of the using teller using teller demo repo you can see here at using uh or github.com IO slash using teller demo as well uh before we get started we'll want to npm install and what this will do is install two packages a hard hat of course and using teller which is a contract that you can npm install uh it's an npm library but inside it is a contract that we can use to really easily access um the teller functions for reading data into our contract to import using teller what we'll need to do is and by the way this the last thing I'll say before I start typing code is that you can actually follow along with this tutorial just like I'm doing it and it will work front to back and it's basically a teller integration which is really cool and once that is done if you actually send me um uh your deployed contract in a um transaction hash of a tip then I will send you an nft that uh that I made I've made 22 of them so there's plenty to go around um and the nft is on open C and each nft is a photograph that I've taken just a little bonus for fun but now that we have npm installed we'll want to import using teller slash contracts you can even see it auto populating here uh using teller.soul okay cool um oh and of course uh it's a contract and not a library in solidity using tellers so we'll want to inherit um using teller from our contracts and so we'll say using teller demo is using teller um I'm gonna get to this in a minute um but before that we'll just fill out our Constructor all we need to do is put in a payable uh teller address um and then as well we want to fill in the um instructor of using teller itself and what this does is essentially is point our contract to uh teller Oracle and for to do that that's really all we have to do we actually don't even need to fill anything in for this tutorial um in the body of our Constructor um and as I was mentioning here we have um uh when it comes to reading values what's more important almost to to the story of reading values or the the procedure that we need to do it is to um understand how date requests are made on Teller and if I open this up um you can see this links to a repo called Data specs in other words it's the specifications of a list of types of data you can request on Teller you can actually request any data arbitrary data on Teller but these are the ones that we've pre-configured and set up so far um you can see here that you may notice there's a query type a query description and query parameters and so you may notice some familiar language URL in a parse string and you'll see that if we want to read value we may need to put together the URL in the parse args in such a way that maybe we can build a query data that you see here and finally a query ID and so you'll see here that we're going to be building a query data we're going to Hash it until the query ID we're going to get our data using a using teller getter and finally we're going to decode our data into a un256 um you'll see here that actually for this type this is a numeric APA API response which in other words means we're going to call an API and get a number back um and you'll see that if we're getting a number back uh we're going to be returning uh you and 256. okay to start we'll build our query data and we actually have a reference here so for example here uh we'll want to put in the query type in an API encoding and after that we'll want to ABI encode the URL that we're requesting and then what we need to parse into uh the Json to get um the number we want so in this case we will actually want to get in this API which is like very long and kind of scary looking um we really just want the count of episodes so our that's why I've called my parse RX info comma count you'll see we want to parse into info and parse it to count like If This Were a python dictionary or in this case it's Json of course so we'll build our query data like we saw in the example bytes memory query data equals ABI dot encode of numeric API response and then an inner ABI encoding of the URL and the parse Arch okay so just to recap to build our query data we'll combine the query type and of course in API encoding we'll combine the query type and the query parameters and convert them into bytes using API encoding next we're going to build the query data which are bytes 32 always as they are a hash um we'll simply keka I always add that extra C by accident [Music] 256. of 4A data finally we can request our data from teller so we're going to call this getter called get current value um and we're gonna paste in our query ID as input and so get current value it always returns three uh always returns three variables uh the first is a Boolean success at the request the second is bytes memory and it's the value that we get um and so since the teller Oracle is data type agnostic um all all um and statistics can support arbitrary data uh get current value will return a bytes in encoding of the value which you can always decode um which we'll do the next step but you can always decode into the data type if you're choosing in this case we continue um the last argument is it's always a time stamp this is the timestamp that the reporters submitted the value but we actually don't really need the success and we don't really need the time stamp so I'm going to take that out but it's just always good to show in case you do want to use them if you Fork this make it a little bit more complex um to decoder data in this case we'll actually just want to return it pieces of view function to recode decode our data we're going to want to ABI decode value and we want to extract u in 256 so we pass in un256 as a second argument in parentheses okay cool I think this is ready to go so let's compile it and by the way while that compiles I do want to mention that uh cool it compiled successfully I want to mention that I set up a DOT end dot example that you can use to put in your private key in node URL for the next step uh which is just deployment to ring could be um so just make sure you have rinky B ether and make sure you have a private key that you can put through ether into um but I didn't really want to go over how ethers works because we we you'll you can find that in any tutorial but um I did write out this tutorial that uh already have I mean excuse me I already wrote out this script and this script has uh points to the teller address on rinky B um which you can actually find a list of our addresses um on the teller docs um our deployment addresses across different networks in case you want to use another Network it's just building a contract Factory deploying the contract and then making sure that's deployed so you can run it and we'll whoops once we run it we will get out um contract address and so either scan typically takes a few minutes to like properly load um like load and display the uh contracts so what we'll do is we'll just move on to the next step which is the final step and is funding our feed um so it's this part is a little bit longer but it's it looks a little intimidating but we can set it up so that um that it all works out and as well if you do want to eventually on your own time read a value um from your contract after the Telly reporter the teller data reporters Network um reads your uh or fulfills your request you can actually paste in the address of your demo here and then call read value and output the result 2 Terminal but anyway uh our last step is funding the feed and so what do we mean by that by finding a feed we mean we want to actually and what we can do using what we call autopay uh payments contract is that we can set up recurring payments um all in solidity with only two transactions or three actually including approval um we can set up recurring payments to the teller data reporters Network to maintain uptime on our data feed and by data feed I mean the query ID that we are requesting to tell her I did paste in um the arguments to the two functions we're going to use from autopay it's setup feed and fun feed um you can reference them when you if you want to replace um the arguments here um I actually if you're wondering how I got the query data and the query ID out from um from my contract I actually went to build um I I went to query ID builder.
herokuapp.com this is a utility that we built um in house that seller it's free to use and as well open source so you can Fork it or even contribute to it if you'd like um all I did was put in numeric API response so that's the query type as we learned and I put in the two string arguments I'm not going to go through the whole thing but basically if I put in some nonsense here you can see that it would generate the query data and the query ID which so if you use your own API with its own parse strings then you could uh use this tool to paste in your own query data inquiry ID um but anyway the next um parameter is the reward as well the start time so when we want to start incentivizing teller reporters um the an interval and window which is a little complex but basically just means how many how frequently you want to set up Windows of time that teller reporters can receive reward for reporting data and finally um before or after that is uh the funding of the feed so that's the setting up of the schedule of the feed and then funding the feed um you can see here is uh feed ID which we create in the previous transaction uh the query ID uh sets the data feed identifier and the amount of trb or teller tokens that we want to put into this data feed or reward in this data feed over time um but just to recap uh they may have been a little confusing but just to recap um what we're going to do is we're going to set up a data feed which is a recurring schedule of dispersing tokens uh to Delta Data reporters on Teller to claim if they report to our query ID to if they report to our data feed and as well um uh we're going to finally fund the feed and we're going to fund the feed with an amount of trb that will disperse over time over that interval schedule so let's run uh npx hard hat scripts uh Slash funv.js and this one is going to take a little bit more time to run uh oh actually not um oh I forgot to add you want I forgot to add that we want to deploy to network ring could be so let me actually MPX hard hat run Scripts deploy Network print could be and so we'll wait for that to run so we always want to make sure that we include the network flag right um and so that's that's uh finished so we'll go back up and run fun feed on rinky B so this uh scripts may take a little bit longer to run because it waits for the transactions to finish but you'll see after each transaction uh the console will output the transaction hash of each transaction so of course we start with um setting up our feed and which doesn't actually cost any trb then we approve some tokens um to the auto pay contract or the payments contract so that we can fund a feed with those tokens as a reference we have on some networks you may want to use um you may want to use okay great vitalik tweet but um you may want to use this account the trb faucet if you tweet on it we'll actually give you um if you tweet like just just like this one um with the network in your address we'll just send you some trb on the network uh that you requested to but as well on this particular contracts that I used some of them will come with a faucet that you can just call on etherscan um which I'll demonstrate right now um the token here if you go to I think you'd be if you paste this address into Brink could be etherscan you'll actually see that there's a faucet in the contract which is really cool um so just put in your address click right connect to web3 of course and you'll get like a very large amount of test trb that you can play around with um thanks for watching I hope you enjoy it and once again if you finish it uh please reach out to me reach out to me if you have any questions in general but if you finish it and you like it and you you get all the way to the end then please reach out as I will give you ownership to an nft of a pretty picture thanks so much this is tally signing off see ya
Automatic transcript — names and jargon may be misspelled.