Skip to content

Beginning Development #5

@AddressXception

Description

@AddressXception

We are finally ready to go!

Now, in order to start developing we should initialize our project with some defaults. Hardhat has a CLI that will deploy a scaffolded project for you. Follow their getting started documentation and Create an Advanced sample project that uses Typescript. This is the create-react-app of blockchain.

Once it is done installing all the npm packages, you have a fully functional project that is ready to go. Try a couple of commands and get familiar with the output

npx hardhat compile

npx hardhat accounts

npx hardhat test

How it works

The magic of hardhat is that it uses a product called Ganache under the hood to run a local private ethereum network on your computer! When you run a unit test, the hardhat framework (along with ethers.js) will abstract away all of the gory details of issuing transactions, serializing their responses, and throwing errors, etc. Hardhat will immediately mine transactions for you as well so you don't have to worry about any of the difficult things that come with blockchain development.

Just write a smart contract, and test it just like you would any javascript application using chai/mocha, or whatever your preferred test framework is.

A note about other tools

There is another large framework called Truffle. Truffle is the OG and a competitor to hardhat, however because of it's legacy it is a bit clunky to work with. In some cases you will see either truffle or hardhat code when you look things up on stack overflow. they have the same concepts but their API's are a little different.

Similarly there is a competing application framework to Ethers called web3.js. Again, it's a similar tool but suffers from years of hacking on its API's and is a bit long in the tooth.

This is, after all, JS development so we have to be on the bleeding edge of tools that barely work or we're "doing it wrong" (tm).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions