Setup and Configuration

⚠️ Production Status: EVM integration is not deployed on mainnet. Available on evm-poc branch. See EVM Integration for details.

This guide covers everything you need to set up your development environment for building dApps on BitBadges Chain with EVM compatibility.

Chain Configuration

Chain ID

The BitBadges Chain EVM uses a custom Chain ID for EVM compatibility:

  • Local Development: 90123

  • Testnet: TBD (contact us for testnet setup)

  • Mainnet: Not deployed (see production status notice)

The Chain ID is configured in app/params/constants.go:

EVMChainID = "90123" // Default for testing

Important: The Chain ID in your genesis file (app_state.evm.params.chain_config.chain_id) must match this value.

RPC Endpoints

BitBadges Chain provides two RPC interfaces:

  1. Tendermint RPC (Port 26657)

    • Used for Cosmos SDK queries and transactions

    • Endpoint: http://localhost:26657

    • Supports standard Cosmos SDK operations

  2. EVM JSON-RPC (Port 8545)

    • Used for Ethereum-compatible operations

    • Endpoint: http://localhost:8545

    • Supports standard Ethereum JSON-RPC methods

    • Required for MetaMask, ethers.js, web3.js, etc.

Starting the Chain with EVM

To start the chain with EVM support, use the --json-rpc.enable flag:

Or use the provided startup script:

The startup script automatically enables EVM JSON-RPC on port 8545.

Note: The EVM module is always enabled in the chain binary. You only need to enable the JSON-RPC server to interact with it via Ethereum-compatible tools (MetaMask, ethers.js, etc.).

MetaMask Configuration

To connect MetaMask to your local BitBadges chain:

  1. Open MetaMask

  2. Go to Settings > Networks > Add Network

  3. Add the following network configuration:

For Local Development:

  • Network Name: BitBadges Local

  • RPC URL: http://localhost:8545 (EVM JSON-RPC)

  • Chain ID: 90123

  • Currency Symbol: BADGE

  • Block Explorer: (Optional, leave blank for local)

Note: Use port 8545 (EVM JSON-RPC), not 26657 (Tendermint RPC).

Getting Test Tokens

After starting your local chain, fund your MetaMask account:

Simple dApp Setup

Project Structure

A typical dApp project structure:

Basic Contract Template

Here's a minimal contract that uses the tokenization precompile:

Deployment Script (TypeScript/ethers.js)

Frontend Integration (React/ethers.js)

Contract Snippets

Helper Library

The repository includes a comprehensive helper library at contracts/libraries/TokenizationHelpers.sol that provides utility functions for:

  • Creating UintRange structs (single values, sequences, full ranges)

  • Creating Balance, CollectionMetadata, TokenMetadata structs

  • Creating empty permission structures

  • Validating ranges and balances

  • Common patterns for ownership times and token IDs

Import and use the helper library:

See the TokenizationHelpers.solarrow-up-right file for all available helper functions.

Common Patterns

Pattern 1: Simple Token Transfer

Pattern 2: Batch Transfer

Pattern 3: Time-Limited Transfer

Pattern 4: Using Helper Library

Pattern 5: Dynamic Store for Compliance

Complete Examples

Counter dApp

For a complete end-to-end example, see the counter-dapparrow-up-right in the repository. It includes:

  • Simple Solidity contract (Counter.sol)

  • Deployment script (TypeScript)

  • Next.js frontend with MetaMask integration

  • Complete setup instructions

ERC-3643 Example Contracts

The contracts/examplesarrow-up-right directory contains production-ready examples:

  1. TwoFactorSecurityToken.sol - Security token with 2FA authentication

  2. RealEstateSecurityToken.sol - Tokenized real estate with KYC/AML

  3. CarbonCreditToken.sol - Carbon credits with vintage tracking

  4. PrivateEquityToken.sol - Private equity fund tokens with lock-ups

Each example demonstrates:

  • Dynamic Stores for compliance registries

  • Time-bound ownership for lock-ups and expirations

  • Complex approval systems

  • Real-world use cases

See the examples READMEarrow-up-right for detailed explanations of each contract.

Troubleshooting

RPC Connection Issues

Problem: Can't connect to RPC endpoint

Solutions:

  • Ensure the chain is running: bitbadgeschaind start --json-rpc.enable --json-rpc.address 0.0.0.0:8545

  • Check if EVM JSON-RPC is enabled in app.toml

  • Try both ports: http://localhost:8545 (EVM) and http://localhost:26657 (Tendermint)

  • Verify the chain is fully synced

MetaMask Connection Issues

Problem: MetaMask can't connect to the network

Solutions:

  • Use the correct Chain ID: 90123 for local development

  • Use EVM JSON-RPC port: http://localhost:8545 (not 26657)

  • Ensure your local chain is running

  • Check MetaMask console for detailed error messages

Transaction Failures

Problem: Transactions fail with "insufficient funds" or revert

Solutions:

  • Fund your account with BADGE tokens:

  • Check gas prices (may need to adjust in MetaMask)

  • Verify approvals are set correctly for token transfers

  • Check contract logs for specific error messages

Contract Deployment Issues

Problem: Contract deployment fails

Solutions:

  • Ensure you have sufficient balance for deployment gas

  • Check that the EVM module is enabled

  • Verify your Solidity version matches the chain's supported version

  • Check deployment script logs for specific errors

Next Steps

Last updated