A newsletter meant to inspire the next generation of readers on AI, Blockchain, and Cyber Security.
A newsletter meant to inspire the next generation of readers on AI, Blockchain, and Cyber Security.

Subscribe to DeadLock

Subscribe to DeadLock
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers


Hello there 👋, today I am going to walk you through the process of integration with Alchemy node in your smart contract project. Our project will be on Ethereum blockchain and we will use Hardhat for framework and solidity programming language for developing smart contracts. Before that let me first introduce you to Alchemy and why we will need that.
If you ever got a chance to read the Ethereum white paper 📄, you might know that developers deploy smart-contract on something called “node“. Node ☋ is a virtual machine that runs EVM a.k.a Ethereum Virtual Machine where the latest synced copy of ledgers 📒 are stored. After deployment of Smart-Contact the changes needed to be broadcasted 📢 the local node so that other nodes can 🥫 added the to there ledger 📒 and synced up.
It's a big hassle for a developer to set up the node and run it and it's also costly to maintain it. Alchemy just do that for you. So that the development experience can be much smoother. Let's start with prerequisite for this project.
Node (latest)
npm/yarn (latest)
Metamask Wallet (chrome extension)
Chrome (recommended)
Code Editor (optional)
let's head to the terminal. Go ahead and cd to the directory you want to work in. Once you're there run these commands:
mkdir alchemy
cd alchemy
npm init --yes
npm install --save-dev hardhatWhat happens here is, you run:
mkdir alchemy to create a directory named "alchemy".
cd alchemy to enter the newly created directory.
npm init --yes to generate an empty npm project without going through an interactive process. The -y stands for yes.
npm install --save-dev hardhat@latest to install Hardhat.

In the same directory where you installed Hardhat run:
Choose the option Create a JavaScript project. Say yes to everything. To run sample projects you will need to install following dependencies.
npm install --save-dev "hardhat@^2.12.3" "@nomicfoundation/hardhat-toolbox@^2.0.0"You can ignore the warnings ⚠ for now.

Now you will see bunch of folders and files in your directory. It's very important to maintain the folder 📂 structure in order to run hardhat properly. Following are the important files 📂 and folders that you have to know.
contracts : This folder contains all the smart-contracts for the project. There will be a sample smart-contract with “.sol“ extension at the end of it.
scripts : This folder contains all the scripts for the test or the deployment of the project. There will be a sample javascript script that will execute the sample smart-contract of the project.
test : This folder contains all the scripts for testing of the project. There will be a sample javascript test script that will execute the testing on sample smart-contract of the project.
hardhat.config.js : This file contain the version of compiler and the APIs for the different types of network. It also contains the private keys of different wallets 💳.
Now create a .env file in the alchemy folder and add the following lines.
HTTP_URL="add-alchemy-http-provider-url-here"
PRIVATE_KEY="add-the-private-key-here"Go to Alchemy and sign up for an account. If you already have an account, log in. Alchemy is a node provider that lets you connect to various different blockchains. We will be using it to deploy our contract through Hardhat. After creating an account, click on Create App on Alchemy, input name and description and select Ethereum, and then select the Goerli network. Click Create App in the bottom left ☜ and then click on View Key. Copy the link given to you in HTTP Provider and add it to the .env file for HTTP_URL.

Go to Metamask and sign up for an account. If you already have an account, log in. To get your private key, you need to export it from Metamask. Open Metamask, click on the three dots, click on Account Details and then Export Private Key. MAKE SURE YOU ARE USING A TEST ACCOUNT THAT DOES NOT HAVE MAINNET FUNDS FOR THIS. Add this Private Key below in your .env file for PRIVATE_KEY variable.
Now we will install dotenv package to be able to import the env file and use it in our config. Open up a terminal pointing at alchemy directory and execute this command.
Now open the hardhat.config.js file, we would add the goerli network here so that we can deploy our contract to the Goerli network. Replace all the lines in the hardhat.config.js file with the given below lines.
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config({ path: ".env" });
const HTTP_URL = process.env.HTTP_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
module.exports = {
solidity: "0.8.9",
networks: {
goerli: {
url: HTTP_URL,
accounts: [PRIVATE_KEY],
},
},
};Compile the contract, open up a terminal pointing at alchemy directory and execute this command.
npx hardhat compileTo test, open up a terminal pointing at alchemy directory and execute this command.
npx hardhat testTo deploy, open up a terminal pointing at alchemy directory and execute this command.
npx hardhat run scripts/deploy.js --network goerli
Hello there 👋, today I am going to walk you through the process of integration with Alchemy node in your smart contract project. Our project will be on Ethereum blockchain and we will use Hardhat for framework and solidity programming language for developing smart contracts. Before that let me first introduce you to Alchemy and why we will need that.
If you ever got a chance to read the Ethereum white paper 📄, you might know that developers deploy smart-contract on something called “node“. Node ☋ is a virtual machine that runs EVM a.k.a Ethereum Virtual Machine where the latest synced copy of ledgers 📒 are stored. After deployment of Smart-Contact the changes needed to be broadcasted 📢 the local node so that other nodes can 🥫 added the to there ledger 📒 and synced up.
It's a big hassle for a developer to set up the node and run it and it's also costly to maintain it. Alchemy just do that for you. So that the development experience can be much smoother. Let's start with prerequisite for this project.
Node (latest)
npm/yarn (latest)
Metamask Wallet (chrome extension)
Chrome (recommended)
Code Editor (optional)
let's head to the terminal. Go ahead and cd to the directory you want to work in. Once you're there run these commands:
mkdir alchemy
cd alchemy
npm init --yes
npm install --save-dev hardhatWhat happens here is, you run:
mkdir alchemy to create a directory named "alchemy".
cd alchemy to enter the newly created directory.
npm init --yes to generate an empty npm project without going through an interactive process. The -y stands for yes.
npm install --save-dev hardhat@latest to install Hardhat.

In the same directory where you installed Hardhat run:
Choose the option Create a JavaScript project. Say yes to everything. To run sample projects you will need to install following dependencies.
npm install --save-dev "hardhat@^2.12.3" "@nomicfoundation/hardhat-toolbox@^2.0.0"You can ignore the warnings ⚠ for now.

Now you will see bunch of folders and files in your directory. It's very important to maintain the folder 📂 structure in order to run hardhat properly. Following are the important files 📂 and folders that you have to know.
contracts : This folder contains all the smart-contracts for the project. There will be a sample smart-contract with “.sol“ extension at the end of it.
scripts : This folder contains all the scripts for the test or the deployment of the project. There will be a sample javascript script that will execute the sample smart-contract of the project.
test : This folder contains all the scripts for testing of the project. There will be a sample javascript test script that will execute the testing on sample smart-contract of the project.
hardhat.config.js : This file contain the version of compiler and the APIs for the different types of network. It also contains the private keys of different wallets 💳.
Now create a .env file in the alchemy folder and add the following lines.
HTTP_URL="add-alchemy-http-provider-url-here"
PRIVATE_KEY="add-the-private-key-here"Go to Alchemy and sign up for an account. If you already have an account, log in. Alchemy is a node provider that lets you connect to various different blockchains. We will be using it to deploy our contract through Hardhat. After creating an account, click on Create App on Alchemy, input name and description and select Ethereum, and then select the Goerli network. Click Create App in the bottom left ☜ and then click on View Key. Copy the link given to you in HTTP Provider and add it to the .env file for HTTP_URL.

Go to Metamask and sign up for an account. If you already have an account, log in. To get your private key, you need to export it from Metamask. Open Metamask, click on the three dots, click on Account Details and then Export Private Key. MAKE SURE YOU ARE USING A TEST ACCOUNT THAT DOES NOT HAVE MAINNET FUNDS FOR THIS. Add this Private Key below in your .env file for PRIVATE_KEY variable.
Now we will install dotenv package to be able to import the env file and use it in our config. Open up a terminal pointing at alchemy directory and execute this command.
Now open the hardhat.config.js file, we would add the goerli network here so that we can deploy our contract to the Goerli network. Replace all the lines in the hardhat.config.js file with the given below lines.
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config({ path: ".env" });
const HTTP_URL = process.env.HTTP_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
module.exports = {
solidity: "0.8.9",
networks: {
goerli: {
url: HTTP_URL,
accounts: [PRIVATE_KEY],
},
},
};Compile the contract, open up a terminal pointing at alchemy directory and execute this command.
npx hardhat compileTo test, open up a terminal pointing at alchemy directory and execute this command.
npx hardhat testTo deploy, open up a terminal pointing at alchemy directory and execute this command.
npx hardhat run scripts/deploy.js --network goerli
No activity yet