How to deploy smart contract?

Kacper Hernacki
4 min readDec 28, 2022

--

Have you ever been wondering how to deploy smart contract in easy steps?

If so, this tutorial is totally for you, go through that and achieve necessary knowledge which will boost your web3 dev career.

There are multiple ways of proceeding the deployment. Below are presented general steps:

Step 1: connecting to the network.

It is a crucial part, it is impossible to add new smart contracts without having an access to the network.

One of the providers which allows the integration is alchemy.

Sign up and create an API key:

“Navigate to the “Create App” page in your Alchemy Dashboard by hovering over “Apps” in the nav bar and clicking “Create App”.

Name your app and choose network, good practice is to firstly, test a deployment on testnet.

Step 2: create a wallet

Deployment has to be made from an account, what means using a crypto wallet connected to the chosen network.

One of the most famous is metamask:

Step 3: add funds to wallet

No matter if you deploy to testnet or mainnet, it is necessary to have some balance, assets on chosen address.

On testnet, you can add “fake coins”. For example on goerli testnet network, you can transfer for free “fake eth”, from goerli faucet.

Here is a service to transfer funds, remember that it is limited.

https://goerlifaucet.com

Step 4: initialize Hardhat project

Install Hardhat for processing entire smart contract directory.

Then initialize project.

It will create clean folder structure for a project. All web3 developers will be able to understand it, because it is not changing through every dapp.

Add contracts to /contracts directory and tests to /tests. Then in /scripts will be stored commands for deployment.

Step 5: write smart contract

Use solidity or another programming language to create own smart contract, write tests and check if it compiles correctly.

Do you know how to test smart contracts? Below is my previous material:

Step 6: connect wallet and node provider to project

It is necessary to pass environmental variables, like private key of a wallet and api url. in a smart contract project directory. It is a practice needed to make a deployment from terminal using for example hardhat.

Example from:

Step: 7 Install ethers.js.

ethers.js is a package which can directly talk with node in a blockchain, by using json rpc. This tool provides various web3 functions which are extremely helpful in deployment.

Step 8: update Hardhat.config file

Use environmental variables to describe the network and wallet from which smart contract will be deployed.

Step 9: compile smart contract & write deployment script

This step ensures that there are no syntax errors and smart contract will work on the blockchain.

Go to /scripts directory and create a deploy.js file.

Hardhat is an amazing tool which will take care of all. “behind the scenes stuff”.

Use following example:

Step 10: deploy smart contract

Navigate to command line and write below command:

Smart contract is now deployed, terminal will show an address on which it exists, you can navigate to blockchain explorer and check it.

This thread was inspired by:

Credits for an author for this article and scripts examples 🙌

--

--

Kacper Hernacki

💻Passionate full-stack developer ⛓Blockchain enthusiastic 📌Involved in Web 3.0 startup ✉️ hernackikacper@gmail.com