How to deploy smart contract?

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

How to deploy smart contract?

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.

Alchemy - the web3 development platform
The most powerful set of web3 development tools to build and scale your dApp with ease. The easy way to build and scale…

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:

The crypto wallet for Defi, Web3 Dapps and NFTs | MetaMask
A safe crypto wallet for digital tokens & NFTs. Join the blockchain and DeFi world.

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:

Deploy Your First Smart Contract
Estimated time to complete this guide: ~15 minutes If you are new to blockchain development and don't know where to…

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:

Deploy Your First Smart Contract
Estimated time to complete this guide: ~15 minutes If you are new to blockchain development and don't know where to…

Credits for an author for this article and scripts examples 🙌


Have you enjoyed my web3 articles/threads? Follow this repo which consists all of the topics:

GitHub - Kacper-Hernacki/100-days-of-web3-challenge-blockchain-free-materials: This is the repo…
This is the repo which consists 100 topics about blockchain/ decentralisation/ web3. There are links to my articles,…