Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Token Distribution & Contract Funding

Hello! Welcome back to the final module of your journey.

In our last lesson, you took the crucial step of verifying your smart contracts on the Ethereum mainnet. This transformed them from opaque bytecode into transparent, auditable pieces of software, complete with a user interface on Etherscan. Your project is now live and trustworthy.

However, being live isn't the same as being operational. Right now, your contracts are like a newly constructed building: the structure is sound, but it's empty. Your token contract might have minted an initial supply to your address, but your staking contract, which is meant to distribute rewards, holds no tokens to give away.

This lesson focuses on furnishing that building. Our learning outcome is to execute the initial token distribution and setup for your project (e.g., funding the staking contract). We'll explore the strategy behind deciding who gets tokens at launch and then perform the critical on-chain actions to make it happen.

The Strategy: Initial Token Distribution (ITD)

Before we move a single token, it's essential to understand the plan. Initial Token Distribution (ITD) is the process of allocating your newly created tokens to various stakeholders to bootstrap the project's economy. This is one of the most critical phases, as it sets the foundation for trust, decentralization, and long-term sustainability.

To understand the core components and best practices of ITD, please read the following article. It provides an excellent overview of why this process is so fundamental to a crypto project's success.

How Initial Token Distribution (ITD) Works in Crypto Projects?

The article 'How Initial Token Distribution (ITD) Works in Crypto Projects?' from MEXC Learn provides a clear and comprehensive guide to the principles of token distribution.

Please read the following sections to understand the strategy behind ITD: Start from the beginning and read until the end of 'Key Components of Initial Token Distribution'. This will cover the definition of ITD, its importance, and the typical allocation categories (Public Sale, Team, Staking Rewards, etc.). Then, jump to the section 'Example of a Proper ITD Model' to see a concrete, balanced example. Pay attention to how different allocations have different vesting schedules to align long-term incentives.

As you've read, a typical allocation includes categories like:

  • Team & Founders: To reward the core contributors.
  • Investors: For those who provided early funding.
  • Ecosystem/Treasury: A fund for future development, marketing, and grants.
  • Staking Rewards: Tokens set aside to incentivize users who stake and secure the network.
  • Liquidity: Tokens to be paired with ETH or another asset on a Decentralized Exchange (DEX).

For our project, we'll focus on a simple but crucial initial distribution step: funding the staking contract.

Planning Our Initial Setup

Let's assume your MyToken contract minted the entire supply to you, the deployer (owner). Our goal is to move a significant portion of these tokens from your wallet to the Staking contract's address. This creates the reward pool from which stakers will be paid.

How much should we send? A common strategy is to allocate a large percentage of the total supply for community incentives. The tutorial you may have followed when building your staking contract suggests a specific figure.

Solidity Tutorial: Creating an ERC20 Staking Contract

Let's revisit a specification from a staking contract tutorial that provides a clear and actionable goal for our initial setup.

Quickly review the 'Specifications' section. Notice the last point: 'Send 80% of the total supply to the ERC20Staking contract'. This is the concrete task we are going to execute.

Our plan is set: We will transfer 80% of the total token supply from the owner's wallet to the deployed staking contract.

Executing the Distribution

There are two primary ways to perform this action: through Etherscan's user interface or programmatically with a Hardhat script. Since you have a developer background, we'll cover both, but the script method is more powerful and repeatable.

A Note on Decimals

Before you transfer anything, remember that ERC-20 tokens have a decimals property. If your token has 18 decimals (the standard), then 1 token is represented by the number 1,000,000,000,000,000,000 (1 with 18 zeros).

If your total supply is, for example, 1,000,000 tokens, the actual value stored in the contract is 1,000,000 * 10**18. When calculating the 80% to transfer, you must use this full number.

Test your understanding!

Your token has a total supply of 500,000 tokens and uses 18 decimals. You want to transfer 80% to your staking contract. What is the exact integer value you need to use for the amount in the transfer function?

Show answer
  1. Calculate 80% of the supply: 500,000 * 0.80 = 400,000 tokens.
  2. Add the decimals: You need to add 18 zeros to this number.
  3. Final value: 400000000000000000000000

A much easier way to handle this in code is using ethers.parseUnits (or ethers.utils.parseEther in older versions):
ethers.parseUnits("400000", 18) would produce the correct value.

Method 1: Using the Etherscan UI

Since you verified your contract in the last lesson, you can use Etherscan's Write Contract tab to perform the transfer.

  1. Go to your ERC-20 token's contract page on Etherscan.
  2. Click on the Contract tab, then the Write Contract sub-tab.
  3. Click the Connect to Web3 button and connect your MetaMask wallet (make sure it's the owner account on the Mainnet).
  4. Find the transfer function. It will have two fields:
    • to (address): Paste the address of your deployed staking contract.
    • amount (uint256): Enter the calculated 80% value, including all the zeros for the decimals.
  5. Click Write and approve the transaction in MetaMask.

This method is quick and easy for one-off actions.

Method 2: Using a Hardhat Script (Recommended)

A more robust and repeatable method is to write a simple Hardhat script. This is great for logging, automation, and reducing manual errors.

  1. Create a new file in your scripts folder named initial-setup.js.
  2. Add the following code. Make sure to replace the placeholder addresses with your actual deployed contract addresses.
const { ethers } = require("hardhat");
require("dotenv").config();

async function main() {
  // --- REPLACE WITH YOUR DEPLOYED CONTRACT ADDRESSES ---
  const tokenAddress = "0xYourERC20TokenAddressHere";
  const stakingContractAddress = "0xYourStakingContractAddressHere";
  // ----------------------------------------------------

  const [deployer] = await ethers.getSigners();
  console.log("Executing initial setup with account:", deployer.address);

  // Get contract instances
  const myToken = await ethers.getContractAt("MyToken", tokenAddress); // Replace "MyToken" with your token's contract name
  
  // 1. Calculate the amount to transfer (80% of total supply)
  const totalSupply = await myToken.totalSupply();
  const amountToTransfer = (totalSupply * BigInt(80)) / BigInt(100);

  // Using ethers' format utility for readability
  console.log(`Total supply is: ${ethers.formatUnits(totalSupply, 18)} tokens`);
  console.log(`Transferring ${ethers.formatUnits(amountToTransfer, 18)} tokens to the staking contract...`);

  // 2. Execute the transfer
  const tx = await myToken.transfer(stakingContractAddress, amountToTransfer);
  await tx.wait(); // Wait for the transaction to be mined

  console.log("✅ Transfer successful!");
  console.log(`Transaction hash: ${tx.hash}`);
  
  // 3. Verify the balance of the staking contract
  const stakingContractBalance = await myToken.balanceOf(stakingContractAddress);
  console.log(`Staking contract now holds: ${ethers.formatUnits(stakingContractBalance, 18)} tokens`);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

To run this script, use the following command. Remember to configure your hardhat.config.js for the mainnet network as we did in the previous lessons.

npx hardhat run scripts/initial-setup.js --network mainnet

Verifying the Distribution On-Chain

Whether you used Etherscan or a Hardhat script, the result is an on-chain transaction. The final step is to verify that it did what you intended.

  1. Check the Transaction: Take the transaction hash from your script's output or MetaMask's activity log and search for it on Etherscan. You should see a success status and the details of the token transfer.

    Transaction Receipt
    This is an example of a transaction receipt for a token transfer on a block explorer. You can see the 'From' address (which will be your owner wallet), the 'To' address (your staking contract), and the exact amount of tokens transferred.

  2. Check the Staking Contract's Balance: Navigate to your staking contract's address on Etherscan. Under the "Token" dropdown in its summary view, you should now see your token listed with the balance of 80% of the total supply.

  3. Check the Token Holders: Go back to your ERC-20 token's Etherscan page and click on the "Holders" tab. You will now see your staking contract listed as one of the top holders of your token!

Congratulations! You have successfully executed a critical part of your project's launch.

Conclusion

In this lesson, you bridged the gap between having deployed contracts and having an operational project. You learned the strategic importance of Initial Token Distribution and executed a key setup task: funding your staking contract with reward tokens.

Key Takeaways:

  • Initial Token Distribution (ITD) is the foundational process of allocating tokens to bootstrap a project's economy and align incentives.
  • A common and vital setup task is to transfer a large portion of the total supply to a staking or rewards contract.
  • You can perform on-chain administrative tasks using Etherscan's UI or, more robustly, through Hardhat scripts.
  • Always verify your actions on-chain using a block explorer to confirm that the state has changed as expected.

Preview of the Next Lesson:

Your project is now set up and funded. However, the ownership of your contracts—which gives god-like powers such as minting new tokens or changing critical parameters—still rests with your personal wallet (an EOA). This is a major security risk. In our next lesson, "Transfer contract ownership to a secure multi-signature wallet," we will mitigate this risk by moving control to a more secure, decentralized entity.

Can't find a good explanation? Sign up and we'll make it for you

Sign up