3c/doc/02_minimal.md

48 lines
1.4 KiB
Markdown
Raw Normal View History

2025-02-10 18:37:19 +01:00
- [Compiling and deploying](#compiling-and-deploying)
- [Interacting with the contract](#interacting-with-the-contract)
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:
```js
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:
```bash
npx hardhat run scripts/deploy.js --network sepolia
```
## Interacting with the contract
You can see it on your favorite block explorer (e.g., [Etherscan](https://etherscan.io/)) 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:
```bash
npx hardhat console --network sepolia
```
```js
const MyToken = await ethers.getContract("WhateverYouNamedIt", "0xYourContractAddress");
await MyToken.totalSupply();
```