How to create your own crypto token, fast

Our goal is to deploy an ERC20 token on the Ethereum network and provide liquidity to it. You may want to complete "the easy way" first otherwise this can be confusing.

We will need:

  • A PC with an internet connection (any internet connection, if your LAN goes offline you open up a WiFi hotspot and continue from there)
  • NodeJS + HardHat OR Foundry
  • Contract to deploy (already in my workspace)
  • script to simulate and deploy (already in my workspace)
  • 5 minutes of our life

How to:

👷‍♂️HardHat
  1. Download the workspace [here] and install requirements
npm i
  1. Check the contract we need to deploy ERC20 contract ...distant cricket noises...

  2. Check the scripts order we need to run (0 & 1 in stepsToExecute) script

  3. Check the actual content of each script we want to run, in our case we want to deploy 150.000 🪙MYT and add 25.000 of them into liquidity with 1.5 ETH

  4. Edit the deployment script replacing what you need (red color = edits on template). I've replaced tokenName, tokenSymbol, amount, amountETH (FYI: You can use emoticons in a string if you add 'unicode' before the " ) script

  5. Prepare for deployment, make a simulation (check if your config is forking the ETH mainnet [link])

npx hardhat run .\scripts\DeployToken.js

simulation 7. Deploy on mainnet

npx hardhat run .\scripts\DeployToken.js --network mainnet

You're done.

Remember

  • You can edit the private key inside the .env environment to use your own account.
  • You can deploy any contract as long as you edit the constructor on the DeployToken.js script
  • You can add an infinite number of tasks to run
  • Task 1 won't work if you don't execute task 0 first but will work if you attach the Token contract

To show the complete steps, i'll do an example forking my local hardhat RPC, who is forking ETH mainnet.

🛠️Foundry
  1. Download the workspace [here] and install Foundry

  2. Check the contract we need to deploy (contracts/erc20/Token.sol) ERC20 contract ...distant cricket noises...

  3. Check the scripts order we need to run and replace (scripts/Erc20/deploy.s.sol)

  • name
  • symbol
  • amount to mint
  • amount of tokens to add to liquidity
  • amount of ETH to add to liquidity
contract RunScripts is Tasks {
    uint public tokenToMint = 1_000_000_000;
    uint public ETHInLiq =    0.00001 ether;
    uint public tokensInLiq;
    
    function run() external broadcast {
    // deploy token
        deployToken("TokenName", "TokenSymbol", tokenToMint);
        tokensInLiq = token.balanceOf(deployerAddress) * 10 / 100; // 10% of tokens

    // approve
        token.approve(routerAddress, tokensInLiq);
    // add liquidity
        addLiquidityETH(
            address(token),
            ETHInLiq,
            tokenToMint,
            tokensInLiq,
            ETHInLiq,
            address(this),
            block.timestamp + 15 minutes
        );
    }
}
  1. run the simulation
forge script .\scripts\Erc20\deploy.s.sol:RunScripts --rpc-url mainnet
  1. deploy on mainnet
forge script .\scripts\Erc20\deploy.s.sol:RunScripts --rpc-url mainnet --broadcast

The HardHat custom config allows us to pre-fund our pkeys with ETH on both forks & localhost networks.
On Foundry, we cannot use all the cheatcodes we use in tests, so we run an Anvil RPC forking ETH, we increment our ETH then we run our scripts.
Will this take longer then HardHat?