Tellor 🛠Reading Tellor Data for Any Use Case - Tally Wiesenberg
ETHGlobal·Sun, Oct 9, 2022, 12:00 AM
Welcome Tally Wiesenberg from Tellor for a workshop titled " Reading Tellor Data for Any Use Case". ETHOnline is our biggest event of the year! Collaborate with thousands of developers and creatives from around the world and win over $300k+ in prizes! We're bringing in 30+ of the biggest teams in web3 to give you access like never before. Learn from ecosystem leaders and build your biggest ideas as the merge nears reality. The future of Ethereum is being written right now, and it's time to make your mark. Links Referenced in Tutorial: Using Tellor Demo's Github Repo - https://github.com/tellor-io/UsingTellorDemo Numeric API response Github Repo - https://github.com/tellor-io/dataSpecs/blob/main/types/NumericApiResponse.md Rick & Morty 'Episode' API - https://rickandmortyapi.com/api/episode Tellor Docs 'Funding a Feed' - https://docs.tellor.io/tellor/getting-data/funding-a-feed Tellor Query Builder - https://tellor.io/queryidbuilder/ Tweet @tallywiesenberg w/ your transaction hash for your 'Tally NFT'! (01:43) --------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
[Applause] [Music] hey everyone my name is tali i'm a dev at teller 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 rinkeby and finally we'll tip to teller or in other words will incentivize we'll pay some trb to incentivize the telereporters to update our data over time before i get started i will be referencing a lot of links 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 color demo repo you can see here at using uh or github.com slash teller dash io slash using teledemo um as well uh before we get started we'll want to npm install and what this will do is install two packages hard hat of course and using teller which is a contract that you can npm install it's an npm library but inside it is a contract that we can use to really easily access the teller functions for reading data into our contract to import using teller what we'll need to do is and by the way um 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 your deployed contract in a 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 openc and each nft is a photograph that i've taken just a little bonus for fun but now that we've 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 contract and so we'll say using teller demo is using teller um i'm going to 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 when it comes to reading values what's more important almost to the story of reading values or 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 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 and 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 to build the query id we're going to get our data um using a using teller getter and finally we're going to decode our data into a uint 256. 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 and you'll see that if we're getting a number back we're going to be returning u 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 abi encoding and after that we'll want to abi encode the url that we're requesting and then what we need to parse into the json to get 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 all right that's why i've called my parse args info comma count you'll see we want to parse into info and parse into account 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 parsers okay so just to recap to build our query data we'll combine the query type and of course in abi encoding we'll combine the query type and the query parameters and convert them into bytes using abi encoding next we're going to build the query data which are bytes32 always as they are a hash um we'll simply catch i always add that extra c by accident uh keck 256 of query data finally we can request our data um from teller so we're going to call this getter called get current value and we're going to paste in our query id as input and so getcurrent value always returns three uh always returns three variables uh the first is a boolean success of 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 instances can support arbitrary data uh getcurrentvalue will return uh 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 the last argument is it's always a time stamp this is the time stamp that the reporter submitted the value but we actually don't really need the success and we don't really need the time stamps so i'm going to take them out but it's just always good to shout in case you do want to use them if you fork this make it a little bit more complex um to decode our data in this case we'll actually just want to return it uses a 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 unto 56 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 n example that you can use to put in your private key and node url for the next step which is just deployment touring could be um so just make sure you have rinkybee ether and make sure you have a private key that you can put the ether into um but i didn't really want to go over how ethers works because 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 rinkybee um which you can actually find a list of our addresses um on the tellerdocs or 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 it's deployed so you can run it and we'll whoops you can run it and once we run it we will get out um contract address and so if this game typically takes a few minutes to like properly load um like load and display the uh contract 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 telereporter the teller data reporters network um reads your uh or it fulfills your request you can actually paste in the address of your demo here and then call read value and output the result to your terminal but anyway 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 payments contract is that we can set up recurring payments um ins 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 um to maintain up time 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 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 went to queryidbuilder.
herokuapp.com this is a utility that we built um in house i tell her 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 could see that it would generate the query data and the query id which so if you use your own api uh with its own parse strings then you could 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 in a window which is a little complex but basically just means um how many how frequently you want to set up uh windows of time that teller reporters can um 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 a 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 the state of feed over time um but just to recap that may have been a little confusing but just to recap what we're going to do is we're going to set up a data feed which is a recurring schedule of dispersing tokens to data data reporters on teller to claim if they report to our query id through if they report to our data feed and as well we're going to finally fund the feed and we're going to fund the feed with an amount of trp that will disperse over time over that interval schedule so let's run uh npx hard hat scripts slash fun feed.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 that we want i forgot to add that we want to deploy to network bring me so let me actually mpx hard hat run scripts deploy network rinkyb 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 rinkybee so this uh script 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 which doesn't actually cost any trv then we approve some tokens um to the autopay contract or the payments contract so that we can fund a feed with those tokens as a reference um 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 uh the trb faucet if you tweet on it will 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 contract that i used uh some of them will come with a faucet that you can just call on etherscan which i'll demonstrate right now um the token here if you go to ring could be if you paste this address into ring could be ether scan 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 trd that you can play around with um thanks for watching i hope you enjoy it and once again if you finish it 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 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 you
Automatic transcript — names and jargon may be misspelled.