Links
Youtube link: https://www.youtube.com/watch?v=gIVDfLPTh_M
Official links: https://linktr.ee/
Summary
Hey everyone, my name is Tally, I'm a dev at Tellor and today I'm going to walk you through how to integrate Tellor on the Harmony network or any EVM compatible chain. In this tutorial we're going to create a sample contract that integrates Tellor we're going to deploy the contract to Harmony main-net we'll report a value to Tellor and then we'll read the value from our smart contract. The first thing that we're going to do is we're going to npm install using Tellor and using Tellor is a npm package that contains a contract called using Tellor that we can import into our contract, our sample contract that we can use to easily access common Tellor getters. To start well that's oh it's done okay cool it's done installing so we'll go ahead and start coding. We'll set up slow the version 0.8.0 and we'll import using Tellor contracts okay now we'll set up our contract. We'll call it Tellor Harmony let's match me in the file and we'll inherit from using Tellor. Okay in our constructor want to pass in payable Tellor address and so Tellor address represents the address that the Tellor oracle sits at on our network of choice which we'll pass in in the deployment script shortly but for now we'll continue with the contract so we'll also set up using seller constructor in the using Tellor constructor all we need to do is pass in the Tellor address and for our constructor that's all we'll do for now we'll make a function and we'll call it so today we'll get the make the usb stop price. We'll call get maker usd spot price and we won't pass in any arguments but we will make it a public view function and we will return this function what we're going to do and this is the typical process for requesting data on Tellor is we're going to make our query data. I'll explain these concepts in a make our query data, make our query id request data, parse the price. To start Tellor supports almost or any query type but what we need to do is format or query in this case we make our usd spot price in a way that Tellor oracle can understand so what we'll do is we'll encode a sort of bytes encoding into bytes this will be our query data this will be bytes memory query data and so we'll do an encoding as I'll demonstrate an abn coding, the string spot price. So, this first argument represents the type of query that we're doing the second argument is an inner avi encoder of two arguments these are the arguments of the spot price so these being the two currencies maker and usd now we have our query id so this is a bytes representation of our spot price request for maker usd spot price. The next step is pretty simple it's a bytes32 and it's an abi encoding excuse me not api encoding it's a hash of the above okay so we have a hash and the hash is actually what we're going to pass in to request data from the oracle to request the data. We're going to return it to full and I'll show you what's in the tuple in a second but we're going to use get data before passing our query id and passed in a timestamp of 30 minutes ago so what this means is that we want to get data on our data feed on our query id from 30 minutes ago and we want to do a time in the past we usually want to use get data before as a best practice because if we use the most current value then we haven't left time for disputes but both functions return three variables the first means success the request the second being the value which is vice memory the third being the timestamp and now we can parse the price so in on Tellor we return values as bytes to support as many return types as possible but what we'll do is to get the price simple we can do abi dot decode value and we know that we want to extract the urine so we pass them into v6 okay and so that compiler doesn't bug us we're actually not going to use these two we're not using in this demo so I'm going to take them out so the compiler doesn't bug us I just got to replace that comma okay cool now I think we're ready to aha yep got to return all right okay so you have a getter that reads Tellor and returns to make the usb spot price let's see if it compiles nice it compiles cool let's write our deployment script now i have a heart coded Tellor address in Harmony. But just for reference you have it right here 0xb32 and as well you can follow along on this repository Tellor Harmony demo under github.comTellorHarmonyx but to continue what we'll do is we'll create a contract factory so color factory equals await ethers dot get contracts factory and we'll pass in the name of our contract color Harmony demo okay now we can say that Tellor factory equals color factory that deploy and here's actually where we want to pass in our constructor argument the color address finally awaits that Tellor factory is deployed the very last thing we want to do here is just print out the address of our deployment so we'll do console.log Tellor factory dot address okay let's run it so to run this we'll do mpx hard hat scripts deployed.js we'll set the network to Harmony and just for reference your hard hat in general like your hardhat config won't come with Harmony by default but in this demo in the repo you'll see I added Harmony and you just have to pass in a node url that Harmony provides for free if you look it up and a private key for your account if you're using a live network like you know obviously you're using a test net or mainnet army make sure you have TRB tokens and Harmony tokens. The TRB stake is 10 TRB of, on Harmony the one TRB token so let's deploy oh whoops I forgot a keyword npx hard hat run there we go nice we have a contract address let's look it up cool contract here's our pipe code that's the version 0.8.4 which is what we use which is what hardhat is using for deployment here cool okay the next thing we want to do is we'll set up Telliot what we'll do here is the first thing is virtual environment and I'm doing this my home directory and you can as well it's perfectly safe I want to say python3 and so I have a special python on my computer that I use for this but python 3 will work perfectly fine oh whoops python 3 will be will work perfectly fine python3 dash then so we'll create python virtual environment next we will want to activate it so we'll say source then activate okay and now as I've copied here we have a special leading edge installation of Telliot it's perfect for Harmony so we'll install it in our virtual environment I'll just give it a second to install nuts okay now that we have Telliot set up what we'll want to do is set up in accounts using chain which is a private key or account encryption program that we have associated with Telliot what you'll want to do is type in change add the name of your account so my account and I already have mine set up because I don't want to type my private key out while screen sharing but I'll walk you through um a sort of an example so chained at my account name and 0x123 private key that's where you put your private key you would paste it in chain to add account name private key and then the chain id that you want to set it up with I've set mine up to use Harmony so I think that's something like that but anyway I have mine set up so I can show you here yep that's me 0x897c and set up with the Harmony chain id okay now to report to tell yet we will do Telliot examples a Harmony so that's my account in Harmony. And then we will do reports so we're going to use the report subcommand and we will do dash p yolo because we want to for the purpose of the demo, we don't want to care about profit calculations so yolo ignores the profit calculations. And we'll do quarry tags we want to report to the query tag associated with the query id the maker usd spot prize and let's just submit once okay cool let's run it okay so I have to enter my password for my private key just confirming these configs I'm already staked so I'll just hit enter but otherwise you would enter 10 or 20 or 30 depending on how many states you want to add just waiting for a confirmation it's nice so I've submitted the value and you can see here that my value I'm here I am 0x a97c and submitted a value so let's see if we can read the value I'm just going to make it quick you can follow along I'm going to make a quick ethers.js script and what I'll do is first connect to the contrast and delete the value and then print the value the first thing we'll do is let me update this address okay cool you'll definitely want to do that easter is dot Tellor equal awake ethers dot get contract next we'll read the value and to do that what we'll do is say let price equal away there's excuse me Tellor demo dot yeah let's I'm just going to copy over since there's no auto complete the name of the function so I don't do spelling error then we'll print the dot okay console. But just because javascript formatting is weird I'm going to convert this to a big end and then divide it by big end of one e over eighteen, so if I don't do this it'll sort of just be unreadable, you'll have a lot of extra zeros so we add the big end casting and cast into a number so that we get a good clean number to read in our console. Okay, so similar to before we'll run npx hard hat run scripts slash. Okay awesome we actually get a value which is really cool we just read that the value of maker usd is 846 dollars according to the Tellor oracle, which is it's awesome. So, to recap we've set up a Tellor Harmony demo where we connect to Tellor using the using Tellor contract and npm package we set up a function that reads that we built we set up a function that reads the spot price of maker usd and we built it using a query data and query id functionality we deployed our contract we submitted a value using the Telliot python cli tool and then we read the value using ethers.js. Thanks for watching and make sure to check out the GitHub.