Creating your Contract
In this guide, we will take you through the entire process, step-by-step to create and launch your smart contract.
Once completed, you will have a smart contract address that essentially acts as a bank and mints new ERC-20 tokens when users send Ether to the said contract address.
Getting Started​
To get started, please follow the steps below:
Cloning the Repository​
Please ensure that you have Git installed. If not, please download and install it from here.
Once installed, open up a terminal window and clone the repository with the following command:
git clone https://github.com/realstorypro/the-media-dao.git
- Git will download the entire repository to your local machine. Once the clone is complete, you can navigate into the repository directory and start working with the files.
Installation​
- Install the dependencies with NPM install.
npm install
- Compile the contract with
npx hardhat compile
- Run Tests with
REPORT_GAS=true npx hardhat test --network hardhat
Customization​
- Navigate to
contracts
directory and open the file namedToken.sol
 - Change the token name and symbol by editing the following line and replacing
Token
andTKN
with the values of your choosing.
constructor(uint256 initialMint, uint256 initialPrice) ERC20("Token", "TKN") {
- Open up
scripts/deploy.ts
and change the following line to suit your requirements.
const token = await Token.deploy(100, ethers.utils.parseEther("0.05"));
The first number represents the number of tokens to be sent to the contract deployer (pre-mint). The second number represents the initial token price when purchased form a Bank (0.05 ether).
- Open up
scripts/etherscan-arguments.js
and modify the arguments to match the values from step 3. Note that the second value is in Wei.
module.exports = [
100,
50000000000000000n
]
Deployment​
In this example we will be deploying to Sepolia Testnet.
Getting the API Keys​
Alchemy​
- Signup for a free Alchemy account.
- On the menubar, click Apps -> Create App.
- Ensure that the new app you are creating is using Sepolia network.
- After the app has been created click on the View Keys button located underneath the main navigation.
- Create
.env
file in the root directory and populate it with the API_KEY with value from API_KEY and API_URL with the value from the HTTPS section.
API_KEY = "API_KEY"
API_URL = "https://eth-sepolia.g.alchemy.com/v2/API_KEY"
Etherscan​
- Visit etherscan.io and signup for a free account.
- Once logged in, press your username on the top right, and select the My profile button.
- Click on the API-KEY button on the left hand side and then press the Add button.
- Add the API key to the .env file you've created in the previous step.
ETHERSCAN_API_KEY = "YOUR_API_KEY"
Deploying to Blockchain​
Run the following command to deploy the smart contract to Sepolia Testnet.
npx hardhat run scripts/deploy.ts --network sepolia
If successful this will return deployed CONTRACT ADDRESS.
Deployed to 0x562B9B7BE96E1687DA93589db0568d80Ec0dADB6
Upload to Etherscan​
The final step is to upload the contract to etherscan so people can read the actual code. Replace CONTRACT_ADDRESS with the contract address from the previous step and run the following command.
npx hardhat verify --constructor-args scripts/etherscan-arguments.js --network sepolia CONTRACT_ADDRESS
Congratulations! You have successfully created and launched a smart contract