Skip to content

Tharun007-TK/gymcoin-dapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Gym Coin Intro

GymToken - ERC20 Token Project

A Hardhat-based Ethereum project for deploying and managing the GymToken (GYM), a standard ERC20 token built with OpenZeppelin contracts.

πŸ“‹ Project Overview

This project demonstrates:

  • ERC20 Token Implementation: A complete token contract using OpenZeppelin standards
  • Hardhat Development Environment: Modern Ethereum development toolkit
  • TypeScript Integration: Type-safe smart contract interactions
  • Multiple Solidity Compiler Support: Configured for different Solidity versions
  • Easy Deployment Scripts: Automated deployment with detailed logging

πŸ—οΈ Project Structure

mytoken/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ Token.sol           # GymToken ERC20 contract
β”‚   β”œβ”€β”€ Counter.sol         # Example counter contract
β”‚   └── Counter.t.sol.bak   # Foundry test file (backup)
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ deploy.ts          # Main deployment script
β”‚   └── send-op-tx.ts      # OP transaction example
β”œβ”€β”€ ignition/
β”‚   └── modules/
β”‚       └── Counter.ts     # Ignition deployment module
β”œβ”€β”€ test/
β”‚   └── Counter.ts         # Test files
β”œβ”€β”€ hardhat.config.ts      # Hardhat configuration
└── package.json          # Dependencies and scripts

πŸͺ™ GymToken Contract Details

  • Name: Gym Token
  • Symbol: GYM
  • Standard: ERC20 (OpenZeppelin implementation)
  • Initial Supply: 1,000,000,000 GYM (1 billion tokens)
  • Decimals: 18 (standard)
  • Features:
    • Transfer functionality
    • Allowance system
    • Minting at deployment
    • Standard ERC20 events

πŸš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Git

Installation

  1. Clone the repository (or navigate to your project directory):
cd C:\Projectx\BlockChain\Ethereum\mytoken
  1. Install dependencies:
npm install
  1. Compile contracts:
npx hardhat compile

πŸ”§ Usage

Compiling Contracts

Compile all Solidity contracts:

npx hardhat compile

Deploying GymToken

Deploy to local Hardhat network:

npx hardhat run scripts/deploy.ts --network hardhat

Deploy to Sepolia testnet:

npx hardhat run scripts/deploy.ts --network sepolia

The deployment script will:

  • Deploy GymToken with 1 billion initial supply
  • Mint all tokens to the deployer's address
  • Display the deployed contract address

Verifying on Etherscan

Verify your contract on Etherscan for better transparency:

npx hardhat verify --network sepolia <CONTRACT_ADDRESS> 1000000000

Replace <CONTRACT_ADDRESS> with your deployed contract address.

πŸ“ Deployed Contracts

Sepolia Testnet

πŸ’» Interacting with GymToken

Using Etherscan

You can interact with the verified contract directly on Etherscan:

  1. Visit the contract page on Sepolia Etherscan
  2. Go to the "Contract" tab and select "Read Contract" to view token information
  3. Go to "Write Contract" to interact with functions like transfer, approve, etc.

Using Hardhat Scripts

Create custom scripts for specific interactions. For example, to check your token balance:

// scripts/checkBalance.ts
const hre = require("hardhat");

async function main() {
  const tokenAddress = "0x5dbB770Daa57c7f345E1e55024F0f06247f89682";
  const accountToCheck = "YOUR_ADDRESS_HERE";

  const token = await hre.ethers.getContractAt("GymToken", tokenAddress);
  const balance = await token.balanceOf(accountToCheck);

  console.log(`GYM Token Balance: ${hre.ethers.formatUnits(balance, 18)} GYM`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run the script with:

npx hardhat run scripts/checkBalance.ts --network sepolia

πŸ” Testing RPC Endpoints

If you experience RPC connection issues, you can test multiple endpoints with the provided script:

npx ts-node scripts/findWorkingRpc.ts

This script will:

1. Test the configured RPC endpoint in your `.env` file
2. Try alternative endpoints if the configured one fails
3. Update your `.env` file with a working endpoint
4. Check your wallet balance

## ⚠️ Troubleshooting

### Common Issues

#### RPC Connection Problems

```plaintext
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.7.2)

Solution:

  • Try changing the RPC URL in your .env file
  • Run npx ts-node scripts/findWorkingRpc.ts to find a working endpoint
  • Increase the timeout in your hardhat.config.ts file

Insufficient Funds

Error: insufficient funds for intrinsic transaction cost

Solution:

  • Get testnet ETH from a Sepolia faucet
  • Check your balance with npx hardhat run scripts/checkBalance.ts --network sepolia

Contract Verification Failed

The constructor arguments don't match

Solution:

  • Ensure you're passing the correct constructor arguments
  • For GymToken: npx hardhat verify --network sepolia <CONTRACT_ADDRESS> 1000000000
βœ… GymToken deployed at: 0x5FbDB2315678afecb367f032d93F642f64180aa3

Testing Deployment

You can interact with the deployed contract using Hardhat console:

npx hardhat console --network hardhat

Example interactions:

// Get contract factory
const Token = await ethers.getContractFactory("GymToken");

// Connect to deployed contract (replace with actual address)
const token = await Token.attach("0x5FbDB2315678afecb367f032d93F642f64180aa3");

// Check token details
await token.name(); // "Gym Token"
await token.symbol(); // "GYM"
await token.totalSupply(); // 1000000000000000000000000000 (1B * 10^18)

🌐 Network Configuration

The project is configured to work with multiple networks. Currently set up for:

  • Hardhat Network: Local development network (default)
  • Localhost: Local Ethereum node (port 8545)

Adding New Networks

To add testnets or mainnet, update hardhat.config.ts:

networks: {
  sepolia: {
    url: "https://sepolia.infura.io/v3/YOUR-PROJECT-ID",
    accounts: ["YOUR-PRIVATE-KEY"]
  }
}

Then deploy with:

npx hardhat run scripts/deploy.ts --network sepolia

πŸ“ Smart Contract Details

GymToken.sol

contract GymToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Gym Token", "GYM") {
        _mint(msg.sender, initialSupply * 10 ** decimals());
    }
}

Key Features:

  • Inherits from OpenZeppelin's ERC20 implementation
  • Mints entire supply to contract deployer
  • No additional minting functionality (fixed supply)
  • Standard transfer and approval mechanisms

Deployment Parameters

  • Initial Supply: 1,000,000,000 tokens (specified in deploy.ts)
  • Deployed to: Contract deployer's address
  • Gas Optimization: Compiler optimization enabled

πŸ§ͺ Development Workflow

1. Make Contract Changes

Edit contracts/Token.sol for any modifications

2. Compile & Check

npx hardhat compile

3. Deploy & Test

npx hardhat run scripts/deploy.ts --network hardhat

4. Verify Deployment

Use Hardhat console or create test scripts to interact with your contract

πŸ› οΈ Customization

Changing Token Parameters

Edit contracts/Token.sol:

constructor(uint256 initialSupply) ERC20("Your Token Name", "SYMBOL") {
    _mint(msg.sender, initialSupply * 10 ** decimals());
}

Modifying Supply

Edit scripts/deploy.ts:

const initialSupply = 5000000000; // 5 billion tokens

Adding Features

Consider adding:

  • Minting: Allow new token creation
  • Burning: Token destruction functionality
  • Pausing: Emergency stop functionality
  • Access Control: Admin roles and permissions

πŸ“š Dependencies

  • @openzeppelin/contracts: Secure, audited smart contract library
  • hardhat: Development environment and task runner
  • ethers: Ethereum library for JavaScript/TypeScript
  • typescript: Type safety and modern JavaScript features

πŸ” Troubleshooting

Common Issues

1. Compilation Errors

npx hardhat clean
npx hardhat compile

2. Deployment Failures

  • Check network connectivity
  • Ensure sufficient ETH for gas fees
  • Verify contract constructor parameters

3. Type Errors

  • Ensure TypeScript dependencies are installed
  • Check import paths and contract names

Getting Help

πŸ“„ License

This project is licensed under the ISC License.

About

This project demonstrates blockchain integration with a professional web application, creating a complete dApp for a fitness economy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages