1.4 KiB
1.4 KiB
This document focuses on the minimal setup required to deploy a smart contract to the Ethereum blockchain. It assumes you have already set up your development environment and have a test Ethereum wallet.
Compiling and deploying
First, modify scripts/deploy.js
in the Hardhat project:
const hre = require("hardhat");
async function main() {
const initialSupply = hre.ethers.parseUnits("1000", 18); // 1000 MTK tokens
const MyToken = await hre.ethers.deployContract("MyToken", [initialSupply]);
await MyToken.waitForDeployment();
console.log(`MyToken deployed to: ${MyToken.target}`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
then, deploy like this:
npx hardhat run scripts/deploy.js --network sepolia
Interacting with the contract
You can see it on your favorite block explorer (e.g., Etherscan) by pasting the contract address.
You can send it via the MetaMask extension by clicking "Send" and pasting the contract address.
You can also interact with it programmatically using the Hardhat console:
npx hardhat console --network sepolia
const MyToken = await ethers.getContract("WhateverYouNamedIt", "0xYourContractAddress");
await MyToken.totalSupply();