Tellor School – HardHat setup May 25th

Tellor School – HardHat setup May 25th

By Tamsay | Tellor | 27 May 2022


Links 

Youtube link: https://www.youtube.com/watch?v=1jIRplpNAz8 

Official links: https://linktr.ee/Tellor 

 

Summary 

Explaining how to use Hardhat. 

 

Walkthrough 

Hey everybody, welcome to another episode of Tellor school. In this exercise we're going to set up a quick HardHat repository. If you're unfamiliar, HardHat is a local testing environment for solidity developers on the Ethereum blockchain where you can test compile and debug your code. HardHat is an awesome tool that the Tellor devs use themselves so we thought it might be useful for any developers looking to contribute to the Tellor ecosystem so as I said it's going to be a fairly quick simple exercise so let's just go ahead and dive in. I'm going to share my screen okay so I'm just in my code editor here I've already made my directory folder which is hh test HardHat test and the first thing that we're going to want to do is initiate our node package manager so that'll just be npm init so I'm just going to hit enter a couple times to complete this npm init. Accepting all the defaults there's not going to be anything really pertaining to HardHat specifically here is this okay yes it is okay so now that we've completed the npm init we'll go ahead and install HardHat and we'll do that with the command npm install. Save dev HardHat, this might take a couple minutes so I'll go ahead and skip ahead. Okay so now that we've installed hard hat let's go ahead and run it with the command npx HardHat and then once we see that beautiful blue HardHat logo it's going to ask us what we want to do. For this exercise we will just be selecting create a basic sample project yes in the root of the project that we are currently in correct. Yes, let's add a git ignore so these are going to be some more parameters that they ask you to set when you're initializing HardHat you're going to want to select just the default parameters if you're getting started and feel free to research them more if you feel like it but for this exercise we'll just go ahead and go with the initial defaults again this might take a couple minutes so go ahead and fast forward all right so now that our HardHat project has been created you'll see here on the left that it's given us the bells and whistles of our solidity contract our node modules scripts test file config file and then at any point if you want to see what kind of commands are available to you then you can just go ahead and run npx HardHat minus minus help and then you'll see here a list of available tasks that we can run so we've already done run. Let's go ahead and do compile here so we'll do npx HardHat compile of course you're going to want to spell HardHat correctly that's actually going to be npx hard hat compile. We're getting there and they were compiled successfully outside of my typo there wasn't much else to change so outside of being able to spell correctly one important thing I want to point out is the solidity version so you want to make sure that the solidity version is up to date so here we have 0.8.4 but in fact in the solidity file we have 0.8.0 so I'm just going to go ahead and update that before we move further. Okay now for the main event this wouldn't be a Tellor school video without somehow incorporating Tellor so we will now update this greater solidity contract with using Tellor library so that it can retrieve the btc usd price using the Tellor oracle first things first we'll just do an npm install using Tellor, this will provide us all the handy functions for easily retrieving oracle data and then we'll go ahead and import using Tellor into our contract like so. I'm just going to be pulling the code from the readme file on our github I'll post a link to that in the description below but don't be alarmed if you don't see me typing the actual syntax as I want to make this as seamless as possible for us all now let's go ahead and update this contract so that it can retrieve the bitcoin price from the Tellor oracle first thing, we'll need to do here is import using Tellor right here on line five and then we'll inherit using Tellor. So, that the contract can have all the functionality associated with using the Tellor oracle so that's just going to be is using Tellor which now means that this contract has access to all functions in using Tellor next thing we'll do is we're going to add the object un256 public btc price and then we're going to pass through the Tellor address into the constructor so that'll just be adding the argument address. And then last but certainly not least we'll add in the actual Tellor function of retrieving the bitcoin price so now we should be able to compile this newly updated contract that is now also utilizing Tellor as its oracle to retrieve the bitcoin price so that'll be an npx HardHat compile I am successful that's going to do it for this exercise I hope it was helpful I'll throw the GitHub link in the description below but feel free to reach out with any questions and we'll see you on the next Tellor school. 

 

How do you rate this article?

5



Tellor
Tellor

In this blog I will post transcriptions of videos made by the Tellor team.

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.