This article is for you if you're new to smart contract and blockchain development and don't know where to begin or if you just want to learn how to install and interact with smart contracts. Using a virtual wallet (Metamask), Solidity, Hardhat, and Alchemy—don't worry if you don't yet understand what any of these terms mean—we will demonstrate how to create and deploy a basic smart contract on the Goerli test network.
Let’s talk about how to program smart contracts.
Access the Ethereum network
The Ethereum chain can be queried in a variety of ways. For the sake of simplicity, we'll use a free account on Alchemy, a platform and API for blockchain developers that enables us to interact with the Ethereum chain without having to run our own nodes. In this tutorial, we'll make use of the platform's developer tools for monitoring and analytics to learn more about the inner workings of our deployment of smart contracts.
Develop your app (and API key)
After creating an Alchemy account, you can develop an app to generate an API key. We'll be able to send requests to the Goerli test network as a result. Check see this guide if you're not familiar with testnets.
By selecting "Create App" after hovering over "Apps" in the nav bar, you may access the "Create App" page on your Alchemy Dashboard. Give your program a descriptive title like "Hello World," choose "Staging" for the Environment (used for app bookkeeping), and pick "Goerli" for your network. Make sure you're choosing the Goerli testnet by checking twice! You're done after clicking "Create app"! The table below should contain your application.
Open a wallet on Ethereum (address)
To send and receive transactions on Ethereum, we require an account. In this tutorial, we'll manage your Ethereum account address using Metamask, a browser-based virtual wallet. Visit this website from the Ethereum foundation to learn more about how transactions on the platform operate.
Here you can get a free download of Metamask and register for an account. Make sure to select the "Goerli Test Network" in the upper right when making an account or logging in if you already have one (so that we aren't working with real money).
Insert ether via a faucet
We will require some fictitious Ethereum in order to deploy our smart contract on the test network. You can go to the Goerli faucet, enter your Goerli account address, and then select "Send Me Eth" to get Ethereum. Due to network traffic, it can take some time to receive your bogus Eth. (At the time this was written, it lasted about 30 minutes.) Soon after, you ought to see Eth in your Metamask account.
Verify your Balance
Let's use the composer tool in Alchemy to issue an eth getBalance request to confirm that our balance is present. The amount of Ethereum in our wallet will be returned.
Launch our project
We must first make a folder for our project. We'll use npm init to start the project now that we're in the project folder. Follow these instructions to install npm if you don't already have it (you'll also need to download Node.js).
Install Hardhat
A development environment called Hardhat is used to create, test, deploy, and debug Ethereum programs. It is beneficial to developers when creating dApps and smart contracts locally before deploying them to the live chain.
Our Hello-World project run inside:
npm install --save-dev hardhat
Create Hardhat project
Inside our hello-world project folder, run:
npx hardhat
You should then see a welcome message and option to select what you want to do. Select “create an empty hardhat.config.js”
Create a sample project
❯ Create an empty hardhat.config.js
Quit
Including project folders
We'll make two new folders to maintain the organization of our project. Open your command line and go to the root directory of your hello-world project.
mkdir contracts
mkdir scripts
We'll save the code for our sample smart contract in contracts/.
We will store scripts to deploy and communicate with our contract in the directory scripts.
Publish our contract.
When the hell are we going to write code, you may be asking. Well, we have reached Step 10 now.
Open your preferred editor and click on the hello-world project (we like VSCode). We will create our HelloWorld.sol smart contract using the programming language Solidity, which is used to create smart contracts.
1.Create a new file called HelloWorld.sol in the "contracts" folder by navigating there.
2.The Ethereum Foundation has provided an example Hello World smart contract that we will be utilizing for this tutorial, which is seen below. The text below should be copied and pasted into your HelloWorld.sol file.
Project integration with Metamask & Alchemy
It's time to link our Metamask wallet, Alchemy account, and smart contract now that they have all been formed.
Each transaction that leaves your virtual wallet needs to be signed with your particular private key. We can securely store our private key (as well as the Alchemy API key) in an environment file to grant our program this permission.
Set up Ether.js
Through the use of more streamlined JSON-RPC protocols, the Ethers.js library facilitates communication with and requests to Ethereum.
Integrating Plugins for more tooling and expanded functionality in Hardhat is really simple. To deploy contracts, we'll make use of the Ethers plugin (Ethers.js has some super clean contract deployment methods).
Write up our contract
Let's create our contract now to make sure everything is operating as it should. One of the built-in hardhat tasks is the compile task.
Compose our deployment script.
It's time to construct our contract deploy script now that our contract has been written and our configuration file is ready to use.
Use our agreement
Finally, we are prepared to launch our smart contract! Congrats! A smart contract was just released into the Ethereum chain.
You can see a few of the JSON-RPC requests that Hardhat/Ethers made on our behalf when we used the deploy() function here. The requests eth sendRawTransaction, which requests to actually write our contract onto the Ropsten chain, and eth getTransactionByHash, which requests to read details about our transaction based on its hash, are two that stand out as particularly significant ones (a typical pattern when sending transactions).
This is the step by step to deploy or program your smart contracts. Pretty easy, right?






















