Developing smart contracts

This guide will let you get started writing Solidity contracts

In this guide we will be going over the following:

  • Setting up a Solidity Project

  • Compiling Solidity Source Code

  • Adding More Contracts

  • Using OpenZeppelin Contracts

About Solidity

We won’t be covering language concepts such as syntax or keywords in this guide. For that, you’ll need to check out the following curated content, which features great learning resources for both newcomers and experienced developers:

With that out of the way, let’s get started!

Setting up a Project

The first step is to install a development tool.

The most popular development framework for Ethereum is Hardhatarrow-up-right, and we cover its most common use with ethers.jsarrow-up-right. The next most popular is Trufflearrow-up-right which uses web3.jsarrow-up-right. Each has its strengths and it is useful to be comfortable using all of them.

In this guide, we will show how to develop, test and deploy smart contracts using hardhat

To get started with Hardhat we will install it in our project directory.

Once installed, we can run npx hardhat. This will create a Hardhat config file (hardhat.config.js) in our project directory.

First contract

We store our Solidity source files (.sol) in a contracts directory. This is equivalent to the src directory you may be familiar with from other languages.

We can now write our first simple smart contract, called Box: it will let people store a value that can be later retrieved.

We will save this file as contracts/Box.sol. Each .sol file should have the code for a single contract, and be named after it.

Compiling Solidity

The Ethereum Virtual Machine (EVM) cannot execute Solidity code directly: we first need to compile it into EVM bytecode.

Our Box.sol contract uses Solidity 0.8 so we need to first configure Hardhat to use an appropriate solc versionarrow-up-right.

We specify a Solidity 0.8 solc version in our hardhat.config.js

Last updated

Was this helpful?