Skip to main content

Deploy Smart Contracts to TeQoin L2

Deploy your Solidity smart contracts to TeQoin L2 using your favorite development framework.
What You’ll Learn:
  • Deploy with Hardhat
  • Deploy with Foundry
  • Deploy with Remix
  • Verify deployment
  • Best practices

🎯 Choose Your Tool

Hardhat

Most PopularJavaScript-based frameworkDeploy →

Foundry

Fast & ModernRust-based frameworkDeploy →

Remix

Browser-BasedNo installation neededDeploy →

🔨 Deploy with Hardhat

Hardhat is the most popular Ethereum development framework.

Prerequisites

# Check Node.js installation
node --version  # Should be v18+

# Check npm
npm --version

Step 1: Create New Project

1

Initialize Project

    # Create project directory
    mkdir my-teqoin-project
    cd my-teqoin-project
    
    # Initialize npm
    npm init -y
    
    # Install Hardhat
    npm install --save-dev hardhat
2

Initialize Hardhat

    # Create Hardhat project
    npx hardhat init
    
    # Choose: "Create a JavaScript project"
    # Accept all defaults
This creates:
    my-teqoin-project/
    ├── contracts/          # Your Solidity contracts
    ├── scripts/           # Deployment scripts
    ├── test/              # Test files
    ├── hardhat.config.js  # Configuration
    └── package.json
3

Install Dependencies

    # Install essential plugins
    npm install --save-dev @nomicfoundation/hardhat-toolbox
    
    # Install OpenZeppelin (optional but recommended)
    npm install @openzeppelin/contracts
    
    # Install dotenv for environment variables
    npm install dotenv

Step 2: Configure for TeQoin

1

Create .env File

    # Create .env file
    touch .env
Add your private key:
.env
    PRIVATE_KEY=your_private_key_here
Never commit .env to Git! Add it to .gitignore:
    echo ".env" >> .gitignore
2

Configure hardhat.config.js

hardhat.config.js
    require("@nomicfoundation/hardhat-toolbox");
    require("dotenv").config();
    
    module.exports = {
      solidity: {
        version: "0.8.20",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200
          }
        }
      },
      networks: {
        // TeQoin L2 Mainnet
        teqoin: {
          url: "https://rpc.teqoin.io",
          chainId: 420377,
          accounts: [process.env.PRIVATE_KEY]
        },
        // TeQoin L2 Testnet
        teqoinTestnet: {
          url: "https://rpc-testnet.teqoin.io",
          chainId: 420377,
          accounts: [process.env.PRIVATE_KEY]
        }
      },
      etherscan: {
        apiKey: {
          teqoin: "your-api-key-here" // Get from explorer.teqoin.io
        },
        customChains: [
          {
            network: "teqoin",
            chainId: 420377,
            urls: {
              apiURL: "https://explorer.teqoin.io/api",
              browserURL: "https://explorer.teqoin.io"
            }
          }
        ]
      }
    };

Step 3: Write Your Contract

contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000000 * 10 ** decimals());
    }
}

Step 4: Compile Contract

# Compile contracts
npx hardhat compile

# Output:
# Compiled 1 Solidity file successfully

Step 5: Create Deployment Script

scripts/deploy.js
const { ethers } = require("hardhat");

async function main() {
  // Get deployer account
  const [deployer] = await ethers.getSigners();
  
  console.log("Deploying contracts with account:", deployer.address);
  console.log("Account balance:", (await ethers.provider.getBalance(deployer.address)).toString());
  
  // Deploy contract
  const MyToken = await ethers.getContractFactory("MyToken");
  const token = await MyToken.deploy();
  
  await token.waitForDeployment();
  
  const address = await token.getAddress();
  
  console.log("MyToken deployed to:", address);
  console.log("Transaction hash:", token.deploymentTransaction().hash);
  
  // Wait for a few confirmations
  console.log("Waiting for confirmations...");
  await token.deploymentTransaction().wait(3);
  
  console.log("Deployment confirmed!");
}

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

Step 6: Deploy to TeQoin

    # Deploy to testnet first (recommended)
    npx hardhat run scripts/deploy.js --network teqoinTestnet
    
    # Output:
    # Deploying contracts with account: 0x...
    # Account balance: 1000000000000000000
    # MyToken deployed to: 0x5E3A9432a2D6eb0c5D362A0A2F58Bc02Db45850D
    # Transaction hash: 0x8551993d9c5625bc8e3e75afc58c0aa2998f95be9eb9bd033875157ce900afe8
    # Waiting for confirmations...
    # Deployment confirmed!
Contract deployed to testnet!

Step 7: Verify Deployment

# Check contract on explorer
# Visit: https://explorer.teqoin.io/address/YOUR_CONTRACT_ADDRESS

# Or verify programmatically
npx hardhat verify --network teqoinTestnet YOUR_CONTRACT_ADDRESS
Learn more about verification →

⚒️ Deploy with Foundry

Foundry is a blazing fast, modern development framework written in Rust.

Prerequisites

# Install Foundry
curl -L https://foundry.paradigm.xyz | bash

# Run foundryup to install forge, cast, anvil
foundryup

# Verify installation
forge --version
cast --version

Step 1: Create New Project

# Create new Foundry project
forge init my-teqoin-project
cd my-teqoin-project

# Project structure:
# src/          - Contracts
# script/       - Deployment scripts
# test/         - Tests
# foundry.toml  - Configuration

Step 2: Configure for TeQoin

foundry.toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.20"
optimizer = true
optimizer_runs = 200

[rpc_endpoints]
teqoin = "https://rpc.teqoin.io"
teqoin_testnet = "https://rpc-testnet.teqoin.io"

[etherscan]
teqoin = { key = "${ETHERSCAN_API_KEY}", url = "https://explorer.teqoin.io/api" }

Step 3: Write Your Contract

src/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000000 * 10 ** decimals());
    }
}

Step 4: Install Dependencies

# Install OpenZeppelin
forge install OpenZeppelin/openzeppelin-contracts

# Remappings are created automatically

Step 5: Compile Contract

# Compile
forge build

# Output:
# [⠊] Compiling...
# [⠒] Compiling 1 files with 0.8.20
# [⠢] Solc 0.8.20 finished in 1.23s
# Compiler run successful!

Step 6: Create Deployment Script

script/Deploy.s.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "../src/MyToken.sol";

contract DeployScript is Script {
    function run() external {
        // Get private key from environment
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        
        // Start broadcasting transactions
        vm.startBroadcast(deployerPrivateKey);
        
        // Deploy contract
        MyToken token = new MyToken();
        
        console.log("MyToken deployed to:", address(token));
        
        vm.stopBroadcast();
    }
}

Step 7: Deploy to TeQoin

    # Set your private key
    export PRIVATE_KEY=your_private_key_here
    
    # Deploy to testnet
    forge script script/Deploy.s.sol:DeployScript \
      --rpc-url teqoin_testnet \
      --broadcast \
      --verify
    
    # Output:
    # [⠊] Compiling...
    # Script ran successfully.
    # MyToken deployed to: 0x5E3A9432a2D6eb0c5D362A0A2F58Bc02Db45850D
    # 
    # ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
    # Total Paid: 0.00123 ETH (123000 gas * avg 10 gwei)
Contract deployed and verified!

Foundry Useful Commands

# Check gas usage
forge test --gas-report

# Run tests
forge test

# Format code
forge fmt

# Get contract size
forge build --sizes

# Interact with contract
cast call CONTRACT_ADDRESS "totalSupply()" --rpc-url teqoin

🌐 Deploy with Remix

Remix is a browser-based IDE - no installation required!

Step 1: Open Remix

Visit https://remix.ethereum.org

Step 2: Create Contract

1

Create New File

  1. In the File Explorer, click ”+” to create new file
  2. Name it MyToken.sol
2

Write Contract

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.20;
    
    contract MyToken {
        string public name = "MyToken";
        string public symbol = "MTK";
        uint256 public totalSupply = 1000000 * 10**18;
        
        mapping(address => uint256) public balanceOf;
        
        constructor() {
            balanceOf[msg.sender] = totalSupply;
        }
        
        function transfer(address to, uint256 amount) public returns (bool) {
            require(balanceOf[msg.sender] >= amount, "Insufficient balance");
            balanceOf[msg.sender] -= amount;
            balanceOf[to] += amount;
            return true;
        }
    }

Step 3: Compile

1

Select Compiler

  1. Click “Solidity Compiler” tab (left sidebar)
  2. Select compiler version: 0.8.20
  3. Click “Compile MyToken.sol”
2

Verify Compilation

✅ Green checkmark appears when compilation succeeds

Step 4: Connect Wallet

1

Open Deploy Tab

Click “Deploy & Run Transactions” tab
2

Select Environment

In “ENVIRONMENT” dropdown, select:
  • “Injected Provider - MetaMask”
3

Connect MetaMask

  1. MetaMask popup appears
  2. Select account
  3. Click “Connect”
  4. Make sure you’re on TeQoin L2 network in MetaMask

Step 5: Deploy

1

Select Contract

In “CONTRACT” dropdown, select MyToken
2

Click Deploy

  1. Click orange “Deploy” button
  2. MetaMask popup appears
  3. Review transaction
  4. Click “Confirm”
3

Verify Deployment

  • Contract appears under “Deployed Contracts”
  • You can interact with it directly in Remix
  • Copy contract address for use in your dApp
Contract deployed!

💰 Deployment Costs

Estimated Gas Costs

Contract TypeGas UsedEstimated Cost (TeQoin L2)
Simple Storage~100,000< $0.01
ERC20 Token~1,200,000~0.050.05 - 0.10
ERC721 NFT~2,500,000~0.100.10 - 0.20
Complex DeFi~4,000,000~0.200.20 - 0.40
Much cheaper than Ethereum L1 where the same deployments would cost $50-500+!

✅ Post-Deployment Checklist

1

Save Contract Address

    # Save to a file
    echo "CONTRACT_ADDRESS=0x..." >> .env
    
    # Or create deployment record
    echo "MyToken: 0x5E3A9432a2D6eb0c5D362A0A2F58Bc02Db45850D" >> deployments.txt
2

Verify on Explorer

Visit https://explorer.teqoin.io/address/YOUR_ADDRESSVerify:
  • ✅ Contract created successfully
  • ✅ Transaction shows “Success”
  • ✅ Contract code is visible (after verification)
3

Test Contract Functions

    # Using Hardhat console
    npx hardhat console --network teqoinTestnet
    
    > const MyToken = await ethers.getContractFactory("MyToken")
    > const token = await MyToken.attach("0x...")
    > await token.totalSupply()
    1000000000000000000000000n
Or use Foundry:
    cast call 0x... "totalSupply()" --rpc-url teqoin_testnet
4

Verify Contract Source

Verify your contract source code on the explorer:Contract Verification Guide →

🔧 Troubleshooting

You don’t have enough ETH to pay for deployment gas.Solution:
  • For testnet: Get ETH from faucet
  • For mainnet: Bridge ETH from L1 to L2
  • Check balance: cast balance YOUR_ADDRESS --rpc-url teqoin
Your wallet’s nonce is out of sync.Solution:
  • Reset MetaMask: Settings → Advanced → Clear activity tab data
  • Or wait a few minutes and try again
The explorer indexer might be delayed.Solution:
  • Wait 1-2 minutes
  • Refresh the explorer page
  • Check the transaction hash directly
Your contract is too large (> 24KB limit).Solution:
  • Enable optimizer in compiler settings
  • Split contract into multiple contracts
  • Use libraries to reduce size
    // hardhat.config.js
    solidity: {
      settings: {
        optimizer: {
          enabled: true,
          runs: 200  // Increase for smaller bytecode
        }
      }
    }
Environment variable not set correctly.Solution:
    # Make sure .env is loaded
    cat .env  # Should show PRIVATE_KEY=...
    
    # Try exporting manually
    export PRIVATE_KEY=your_key_here
    
    # For Hardhat, check dotenv is required
    # Add to hardhat.config.js:
    require("dotenv").config();

📊 Deployment Comparison

FeatureHardhatFoundryRemix
Setup Time5 minutes3 minutes0 minutes
SpeedMediumFastSlow
TestingExcellentExcellentBasic
Gas ReportsYesYesNo
Best ForTeamsAdvanced devsBeginners
LanguageJavaScriptRust/SolidityBrowser

🎯 Next Steps

Verify Your Contract

Verify source code on block explorer

Integrate with Frontend

Connect your contract to a dApp

Write Tests

Test your contract thoroughly

Deploy to Mainnet

After testing, deploy to production

💡 Best Practices

Always Deploy to Testnet First
  1. Deploy to testnet
  2. Test all functions
  3. Get community feedback
  4. Audit if handling significant value
  5. Only then deploy to mainnet
Use Environment VariablesNever hardcode private keys in your code:
// ❌ NEVER DO THIS
const privateKey = "0x1234...";

// ✅ ALWAYS DO THIS
const privateKey = process.env.PRIVATE_KEY;
Keep Deployment RecordsMaintain a file with all your deployments:
deployments.txt
# TeQoin Testnet
MyToken: 0x5E3A9432a2D6eb0c5D362A0A2F58Bc02Db45850D
MyNFT: 0x1234567890abcdef1234567890abcdef12345678

# TeQoin Mainnet
MyToken: 0xabcdef1234567890abcdef1234567890abcdef12

Contract deployed? Now verify it on the block explorer