Skip to content

feat: BSC testnet support — deploy escrow on Chapel and wire USDT/USDC #10

Description

@AgrimTawani

Overview

Add BSC (BNB Smart Chain) as a live chain on CryptoBazaar. The escrow contract is pure EVM/Solidity — the same CryptoBazaarEscrow.sol we already run on Polygon Amoy deploys unchanged to BSC Chapel testnet. This is mostly infrastructure + frontend wiring work.


Why BSC

BSC is the most popular chain for USDT volume in India. A large portion of Indian crypto users hold BNB and use PancakeSwap. Gas fees on BSC are ~$0.01–0.05 USD, comparable to Polygon, making it viable for small trades.


Current State

  • CryptoBazaarEscrow.sol is already deployed on Polygon Amoy (testnet).
  • The sell page (frontend/src/app/marketplace/sell/page.tsx) hardcodes amoyChain (chainId 80002), USDC_ADDR, and ESCROW_ADDR — no chain selection exists yet.
  • The trade page (frontend/src/app/marketplace/[id]/page.tsx) also hardcodes amoyChain and the Polygon escrow contract.
  • The DB schema and API already have chain: "BSC" as a valid enum value.
  • isEvm in the trade page correctly includes BSC: order.chain === "POLYGON" || order.chain === "BSC".

Implementation Plan

1 — Deploy contract to BSC Chapel (chainId 97)

BSC Chapel testnet is fully EVM-compatible. No contract changes needed.

# in contracts/evm/
forge script script/Deploy.s.sol \
  --rpc-url https://data-seed-prebsc-1-s1.binance.org:8545 \
  --broadcast \
  --verify
  • Get test BNB from: https://testnet.bnbchain.org/faucet-smart
  • Find or deploy a test USDT token on Chapel (BSC doesn't have an official test USDT; deploy a mintable ERC-20 mock and call setWhitelist on the escrow).
  • Save the deployed addresses to .env as NEXT_PUBLIC_ESCROW_BSC_ADDRESS and NEXT_PUBLIC_CHAPEL_USDT_ADDRESS.

2 — Update sell page for multi-chain

Currently the sell page hardcodes Polygon. Need to:

  • Add a Chain selector (Polygon / BSC) in the form.
  • Based on selected chain, resolve the correct escrowContract, tokenContract, and chain object (defineChain(80002) for Polygon Amoy, defineChain(97) for Chapel).
  • Pass the selected chain to the DB via the existing POST /api/orders body field chain.
// rough shape
const chainConfig = {
  POLYGON: {
    chain: defineChain(80002),
    escrowAddr: process.env.NEXT_PUBLIC_ESCROW_POLYGON_ADDRESS,
    tokenAddr: process.env.NEXT_PUBLIC_AMOY_USDC_ADDRESS,
    asset: "USDC",
  },
  BSC: {
    chain: defineChain(97),
    escrowAddr: process.env.NEXT_PUBLIC_ESCROW_BSC_ADDRESS,
    tokenAddr: process.env.NEXT_PUBLIC_CHAPEL_USDT_ADDRESS,
    asset: "USDT",
  },
};

3 — Update trade page for multi-chain

The trade page currently hardcodes amoyChain and the Polygon escrow contract. It needs to resolve both from order.chain:

const chainCfg = order.chain === "BSC"
  ? { chain: defineChain(97), escrowAddr: process.env.NEXT_PUBLIC_ESCROW_BSC_ADDRESS }
  : { chain: defineChain(80002), escrowAddr: process.env.NEXT_PUBLIC_ESCROW_POLYGON_ADDRESS };

const escrowContract = getContract({
  client: thirdwebClient,
  chain: chainCfg.chain,
  address: chainCfg.escrowAddr as `0x${string}`,
});

All prepareContractCall calls already use escrowContract as a reference so they'll automatically pick up the right chain once the contract object is dynamic.

4 — ThirdWeb wallet — no changes needed

ThirdWeb v5 supports BSC natively. defineChain(97) is enough. The user's MetaMask will prompt a network switch if they're on the wrong chain. The existing AutoConnect and walletOk guard work as-is.

5 — Vercel env vars

Add to Vercel (production + preview):

NEXT_PUBLIC_ESCROW_BSC_ADDRESS=0x...
NEXT_PUBLIC_CHAPEL_USDT_ADDRESS=0x...

Test Procedure

  1. Get Chapel BNB from the faucet.
  2. Mint test USDT to the seller wallet (call mint() on the mock token).
  3. Open /marketplace/sell, select BSC, post an order — confirm MetaMask switches to Chapel (chainId 97), two popups fire (approve + createOrder).
  4. Open order in a second browser session as buyer — confirm lockOrder fires on Chapel.
  5. Submit payment proof — confirm markPaid fires on Chapel.
  6. Confirm payment as seller — confirm confirmPayment fires and USDT lands in buyer wallet.
  7. Verify the ✓ on-chain ↗ link in the marketplace goes to the BSC testnet explorer (testnet.bscscan.com).

Files to Touch

File Change
contracts/evm/script/Deploy.s.sol Add Chapel deploy target
frontend/src/app/marketplace/sell/page.tsx Chain selector, dynamic contract resolution
frontend/src/app/marketplace/[id]/page.tsx Dynamic contract resolution from order.chain
frontend/src/lib/explorer.ts Add BSC Chapel explorer URL mapping
.env.example Document new BSC env vars

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions