Made with ❤ by Roqqet Media
- hardhat 2
- alchemy
Install NPM packages
yarn install
# or
npm install
Learn how to deploy smart contracts to the Sepolia testnet, the preferred Ethereum blockchain for testing decentralized applications.
To get started, create your account on Alchemy by clicking on this link: ** https://dashboard.alchemy.com/signup/?a=deploy-to-sepolia
After creating an Alchemy account, you can generate an API key by creating an app. With this key, we can make requests to the Sepolia test network. To create an app, click on the "Create App" button located in your Alchemy Dashboard.
Name and describe your app, select Ethereum as the chain, and Sepolia as the network. Finally, create the app.
To send and receive transactions on Ethereum, you'll need an Ethereum account. To get started, you can download Metamask for free and create an account. Once you have an account, you'll need to switch to the Sepolia Network.
Follow the steps below to switch:
In the blank boxes, enter the details mentioned in the Sepolia Testnet section. Then, click "Save" and you're all set.
To deploy our smart contract on the test network, we need some fake Eth. To get Eth, you can visit the Sepolia faucet and enter your Sepolia account address. Then click on "Send Me Eth". It may take a while to receive your fake Eth because of network traffic. You should see the Eth in your Metamask account soon after.
To send any transaction from your virtual wallet, you need to sign it with your unique private key. But how can you securely provide your program with this permission? The solution is simple: you can safely store your private key (as well as your Alchemy API key) in an environment file.
To get private key from your metamask wallet,
To get HTTP URL from your alchemy account, see the below steps.
For your private key, follow these instructions. And for the HTTPS URL, just check out the steps below.
Your .env
file should look like this:
ALCHEMY_TESTNET_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/your-api-key
TESTNET_PRIVATE_KEY=your-private-key
- you can copy
.env.example
file as well.
Let's deploy our smart contract. Open your command line and enter the following command:
npx hardhat run deployments/deploy.js --network sepolia
After executing the previous command, you should see something like this:
Contract Deployed to Address: 0xD80C8976a4EB599b11c831a5470f95CfBD0E99D5
Go to the Sepolia etherscan and search for our contract with the printed address.
We should able to see that it has been deployed successfully.
Ensure that the From address matches your Metamask account address. The To address should display "Contract Creation", but upon clicking the transaction, we will see our contract address in the To field.
You can check the deployment status in the Alchemy Dashboard.
Go to your app, scroll to the bottom, and you will see something like this.
npx hardhat run scripts/deploy.ts
After executing the previous command, you should see something like this:
Contract Deployed to Address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
npx hardhat test