Deploying a Smart Contract

Learn how to deploy a smart contract using web3.js

Now, we have everything we need to write an application that will deploy our smart contract to the Goerli network. In this lesson, we'll write a script in JavaScript that'll use the web3.js library to interact with the Goerli network through Infura. While the applications we will build in this chapter will be straightforward, we can use the same principles to create more complex applications that use the Web3 API.

Creating a project

To start working on our application, we first need to create a JavaScript project and add dependencies to it. To create a new project, we'll run the npm init command:

npm init -y
Creating a JavaScript project

This command will generate a new package.json file containing information about our project, including its dependencies. We also add the -y flag that instructs npm to use default settings instead of prompting us about how to configure our project.

Having created a JavaScript project, we can now download dependencies for our project using the following npm install command:

npm install web3 dotenv
Installing dependencies

For this demo, we only need two dependencies:

  • web3: This is a package for the web3.js library that we'll use to interact with an Ethereum network.

  • dotenv: This is a package for reading .env files where we're storing the configuration parameters for our ...