Documentation Index Fetch the complete documentation index at: https://docs.teqoin.io/llms.txt
Use this file to discover all available pages before exploring further.
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
Hardhat Most Popular JavaScript-based framework Deploy →
Foundry Fast & Modern Rust-based framework Deploy →
Remix Browser-Based No installation needed Deploy →
🔨 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
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
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
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
Create .env File
# Create .env file
touch .env
Add your private key: PRIVATE_KEY = your_private_key_here
Never commit .env to Git! Add it to .gitignore: echo ".env" >> .gitignore
Configure 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
// 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
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
Deploy to Mainnet
# 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! # Deploy to mainnet (use with caution!)
npx hardhat run scripts/deploy.js --network teqoin
# Output:
# Deploying contracts with account: 0x...
# MyToken deployed to: 0x...
Double-check everything before deploying to mainnet:
Contract code audited
Tested thoroughly on testnet
Sufficient ETH for deployment
Private key is secure
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
[ 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
// 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
// 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
Deploy to Testnet
Deploy to Mainnet
# 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! # Deploy to mainnet
forge script script/Deploy.s.sol:DeployScript \
--rpc-url teqoin \
--broadcast \
--verify
Always test on testnet first before deploying to mainnet!
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
Create New File
In the File Explorer, click ”+” to create new file
Name it MyToken.sol
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
Select Compiler
Click “Solidity Compiler” tab (left sidebar)
Select compiler version: 0.8.20
Click “Compile MyToken.sol”
Verify Compilation
✅ Green checkmark appears when compilation succeeds
Step 4: Connect Wallet
Open Deploy Tab
Click “Deploy & Run Transactions” tab
Select Environment
In “ENVIRONMENT” dropdown, select:
“Injected Provider - MetaMask”
Connect MetaMask
MetaMask popup appears
Select account
Click “Connect”
Make sure you’re on TeQoin L2 network in MetaMask
Step 5: Deploy
Select Contract
In “CONTRACT” dropdown, select MyToken
Click Deploy
Click orange “Deploy” button
MetaMask popup appears
Review transaction
Click “Confirm”
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 Type Gas Used Estimated Cost (TeQoin L2) Simple Storage ~100,000 < $0.01 ERC20 Token ~1,200,000 ~0.05 − 0.05 - 0.05 − 0.10 ERC721 NFT ~2,500,000 ~0.10 − 0.10 - 0.10 − 0.20 Complex DeFi ~4,000,000 ~0.20 − 0.20 - 0.20 − 0.40
Much cheaper than Ethereum L1 where the same deployments would cost $50-500+!
✅ Post-Deployment Checklist
Save Contract Address
# Save to a file
echo "CONTRACT_ADDRESS=0x..." >> .env
# Or create deployment record
echo "MyToken: 0x5E3A9432a2D6eb0c5D362A0A2F58Bc02Db45850D" >> deployments.txt
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
🔧 Troubleshooting
'Insufficient funds' error
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
Contract deployed but not showing on explorer
The explorer indexer might be delayed. Solution:
Wait 1-2 minutes
Refresh the explorer page
Check the transaction hash directly
'Contract creation code storage out of gas'
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
}
}
}
Private key not found / Invalid private key
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
Feature Hardhat Foundry Remix Setup Time 5 minutes 3 minutes 0 minutes Speed Medium Fast Slow Testing Excellent Excellent Basic Gas Reports Yes Yes No Best For Teams Advanced devs Beginners Language JavaScript Rust/Solidity Browser
🎯 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
Deploy to testnet
Test all functions
Get community feedback
Audit if handling significant value
Only then deploy to mainnet
Use Environment Variables Never hardcode private keys in your code: // ❌ NEVER DO THIS
const privateKey = "0x1234..." ;
// ✅ ALWAYS DO THIS
const privateKey = process . env . PRIVATE_KEY ;
Keep Deployment Records Maintain a file with all your deployments: # TeQoin Testnet
MyToken: 0x5E3A9432a2D6eb0c5D362A0A2F58Bc02Db45850D
MyNFT: 0x1234567890abcdef1234567890abcdef12345678
# TeQoin Mainnet
MyToken: 0xabcdef1234567890abcdef1234567890abcdef12
Contract deployed? Now verify it on the block explorer →