What are EVM Chains?
EVM (Ethereum Virtual Machine) chains are blockchains that are compatible with Ethereum smart contracts. G3Engine supports:
- Ethereum - The original smart contract platform
- Polygon - Low-cost, fast Ethereum sidechain
- Binance Smart Chain (BSC) - High-performance EVM chain
- Arbitrum - Ethereum Layer 2 with low fees
- Optimism - Another Ethereum Layer 2 solution
- Any other EVM-compatible network
Why Use EVM Chains?
Pros:
- Largest Web3 ecosystem and user base
- Most wallets and tools support Ethereum
- Wide variety of DeFi protocols to integrate
- Battle-tested smart contract infrastructure
Cons:
- Higher gas fees (especially on Ethereum mainnet)
- Slower transaction times than Solana
- More expensive for high-frequency game actions
For games with frequent transactions, consider using Polygon or an L2 like Arbitrum instead of Ethereum mainnet to keep gas fees low.
Wallet Support
G3Engine supports EVM wallets through Web3 wallet adapters:
- MetaMask - Most popular Ethereum wallet
- WalletConnect - Connect mobile wallets
- Coinbase Wallet - User-friendly option
- Rainbow - Modern, beautiful wallet
- Any wallet supporting the Web3 standard
Network Configuration
Configure EVM networks in your game settings:
interface EVMNetwork {
chainId: number; // Network ID (1 for Ethereum, 137 for Polygon)
name: string; // Display name
rpcUrl: string; // RPC endpoint
blockExplorer: string; // Etherscan, Polygonscan, etc.
nativeCurrency: {
name: string; // "Ether", "MATIC", etc.
symbol: string; // "ETH", "MATIC", etc.
decimals: number; // Usually 18
};
}
Common Networks
Ethereum Mainnet
{
chainId: 1,
name: "Ethereum",
rpcUrl: "https://eth-mainnet.g.alchemy.com/v2/YOUR-KEY",
blockExplorer: "https://etherscan.io",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }
}
Polygon
{
chainId: 137,
name: "Polygon",
rpcUrl: "https://polygon-rpc.com",
blockExplorer: "https://polygonscan.com",
nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18 }
}
Goerli Testnet (for testing)
{
chainId: 5,
name: "Goerli",
rpcUrl: "https://goerli.infura.io/v3/YOUR-KEY",
blockExplorer: "https://goerli.etherscan.io",
nativeCurrency: { name: "Goerli Ether", symbol: "ETH", decimals: 18 }
}
Connecting a Wallet
Players connect their EVM wallet similar to Solana:
- Click Web3 panel in your game
- Select their wallet (MetaMask, WalletConnect, etc.)
- Choose the network (or auto-switch if configured)
- Approve the connection
Always check that the player is on the correct network. MetaMask users may need to manually switch networks or approve an automatic network switch.
ERC-20 Tokens (Game Tokens)
ERC-20 is the standard for tokens on EVM chains.
Token Structure
interface ERC20TokenInfo {
address: string; // Token contract address
name: string; // Token name
symbol: string; // Token symbol (e.g., "MGT")
balance: number; // Player's balance
decimals: number; // Usually 18 for ERC-20
imageUri?: string; // Token logo
}
Reading Token Balance
// Pseudo-code (actual implementation uses web3.js or ethers.js)
const balance = await tokenContract.balanceOf(playerAddress);
const decimals = await tokenContract.decimals();
const readableBalance = balance / (10 ** decimals);
Transferring Tokens
// Player approves spending tokens
await tokenContract.approve(gameContractAddress, amount);
// Game contract spends tokens
await gameContract.spendTokens(tokenAddress, amount);
ERC-721 NFTs (Collectibles)
ERC-721 is the standard for NFTs on EVM chains.
NFT Structure
Similar to Solana NFTs:
interface ERC721NFTInfo {
contractAddress: string; // NFT collection contract
tokenId: string; // Unique token ID within collection
name: string; // NFT name
imageUri: string; // NFT image URL
attributes?: Array<{ // NFT traits
trait_type: string;
value: string;
}>;
}
Checking NFT Ownership
// Check if player owns a specific NFT
const owner = await nftContract.ownerOf(tokenId);
const playerOwnsNFT = owner.toLowerCase() === playerAddress.toLowerCase();
// Check how many NFTs player owns in a collection
const balance = await nftContract.balanceOf(playerAddress);
Smart Contract Interaction
G3Engine can interact with your custom smart contracts:
Contract ABI
Provide the contract ABI (Application Binary Interface):
const gameContractABI = [
{
"inputs": [{"type": "uint256", "name": "level"}],
"name": "claimReward",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
];
Calling Contract Functions
import { ethers } from 'ethers';
const contract = new ethers.Contract(
contractAddress,
gameContractABI,
signer
);
// Call a function
const tx = await contract.claimReward(playerLevel);
await tx.wait(); // Wait for confirmation
Gas Fees
Unlike Solana, EVM transactions require gas fees that can vary significantly:
Estimating Gas
const gasEstimate = await contract.estimateGas.claimReward(level);
const gasPrice = await provider.getGasPrice();
const totalCost = gasEstimate * gasPrice;
console.log(`Transaction will cost ~${ethers.utils.formatEther(totalCost)} ETH`);
Gas fees on Ethereum mainnet can be very high (10−100+ per transaction). Always warn players about gas costs before they sign transactions.
Gas Optimization Tips
- Use Polygon or L2s instead of Ethereum mainnet
- Batch multiple actions into one transaction
- Use off-chain solutions (Layer 2, sidechains)
- Consider gasless transactions (meta-transactions)
Transaction Tracking
Track EVM transactions similar to Solana:
interface EVMTransaction {
hash: string; // Transaction hash
type: string; // 'token_transfer', 'nft_mint', etc.
status: 'pending' | 'confirmed' | 'failed';
blockNumber?: number; // Block number when confirmed
gasUsed?: number; // Actual gas used
gasPrice?: number; // Gas price paid
}
Viewing on Block Explorer
Link to Etherscan or similar:
const explorerUrl = `https://etherscan.io/tx/${transactionHash}`;
Token Gating with ERC-20/721
Require players to hold tokens or NFTs:
// Check ERC-20 token balance
const tokenBalance = await tokenContract.balanceOf(playerAddress);
const hasAccess = tokenBalance >= requiredAmount;
// Check ERC-721 NFT ownership
const nftBalance = await nftContract.balanceOf(playerAddress);
const hasNFT = nftBalance > 0;
Multi-Chain Support
G3Engine can support multiple EVM chains simultaneously:
const supportedChains = [
{ chainId: 1, name: 'Ethereum' },
{ chainId: 137, name: 'Polygon' },
{ chainId: 42161, name: 'Arbitrum' }
];
// Player can switch between chains
if (currentChainId !== requiredChainId) {
await switchNetwork(requiredChainId);
}
Switching Networks
Request the player to switch networks:
try {
await provider.send('wallet_switchEthereumChain', [
{ chainId: `0x${chainId.toString(16)}` }
]);
} catch (error) {
// If network not added, add it
if (error.code === 4902) {
await provider.send('wallet_addEthereumChain', [networkConfig]);
}
}
RPC Providers
Use dedicated RPC providers for better performance:
- Alchemy - Reliable with excellent free tier
- Infura - Industry standard
- QuickNode - Fast and feature-rich
- Ankr - Multi-chain support
Public RPC endpoints are often rate-limited. Use a dedicated provider for production games.
Development vs Production
Development (Testnets)
- Use Goerli (Ethereum), Mumbai (Polygon), or other testnets
- Free test tokens from faucets
- No real money at risk
Production (Mainnets)
- Thoroughly test on testnets first
- Get security audits for custom contracts
- Start on lower-fee chains (Polygon, Arbitrum)
- Consider subsidizing gas for players
Next Steps
Solana Integration
Learn about Solana as an alternative
Token Management
Design your game token economy