A modern React.js Web3 frontend for the Counterstake Bridge, enabling cross-chain transfers between Ethereum, BSC, and 3DPass networks using MetaMask integration.
- π Cross-Chain Transfers: Transfer tokens between ETH, BSC, and 3DPass networks
- π MetaMask Integration: Seamless wallet connection and network switching
- π¨ Modern UI: Beautiful, responsive design inspired by 3DPass wallet
- β‘ Real-time Updates: Live balance updates and transaction status
- π‘οΈ Security: Trustless counterstake mechanism with automated assistants
- π± Mobile Responsive: Works perfectly on desktop and mobile devices
- Ethereum (Mainnet & Goerli Testnet)
- 3DPass (Mainnet & Testnet)
- ETH (Native)
- USDT
- P3D (Native, ERC20 Precompile at
0x0802) - wUSDT (Wrapped USDT, ERC20 Precompile at
0xde)
Note: In 3DPass, all tokens (including the native P3D) are accessed through ERC20 precompile addresses, not through native token mechanisms like other networks.
- Node.js 16+ and pnpm
- MetaMask browser extension
- Access to supported networks in MetaMask
-
Clone the repository
git clone <repository-url> cd bridge-frontend
-
Install dependencies
pnpm install
-
Configure networks (Optional) Edit
src/config/networks.jsto update RPC URLs and contract addresses for your deployment. -
Start the development server
pnpm dev # or pnpm start -
Open your browser Navigate to
http://localhost:3000
Update the network configuration in src/config/networks.js:
export const NETWORKS = {
ETHEREUM: {
id: 1,
name: 'Ethereum',
rpcUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY',
contracts: {
counterstakeFactory: '0x...',
assistantFactory: '0x...',
oracle: '0x...',
},
// ... other config
},
// ... other networks
};Create a .env file in the root directory:
REACT_APP_INFURA_KEY=your_infura_key_here
REACT_APP_ALCHEMY_KEY=your_alchemy_key_here
REACT_APP_3DPASS_RPC_URL=https://rpc-http.3dpass.org- Click "Connect Wallet" in the header
- Approve the MetaMask connection request
- Ensure you're on a supported network
- Select Source Network: Choose the network you're transferring from
- Select Source Token: Choose the token to transfer
- Select Destination Network: Choose the target network
- Select Destination Token: Choose the token to receive
- Enter Amount: Specify the transfer amount
- Enter Destination Address: Provide the recipient address
- Review Stake: Check the required stake amount
- Initiate Transfer: Click "Initiate Transfer" and confirm in MetaMask
The counterstake bridge requires a security deposit (stake) for each transfer:
- Stake Ratio: Typically 10-20% of transfer amount
- Purpose: Ensures honest behavior through economic incentives
- Return: Stakes are returned after successful transfer completion
- Risk: Stakes can be lost if fraudulent transfers are attempted
- Header: Wallet connection, network switching, navigation
- BridgeForm: Main transfer interface with validation
- Web3Context: Global Web3 state management
- App: Main application layout and routing
The frontend includes special handling for 3DPass's unique ERC20 precompile system:
- Precompile Detection: Automatically detects and handles 3DPass precompile addresses
- Unified Interface: All tokens (including P3D) are treated as ERC20 tokens
- Asset Mapping: Maps precompile addresses to substrate asset IDs
- Validation: Special validation for 3DPass precompile transactions
- Contract Integration: Uses modified Export3DPass and Import3DPass contracts
- Automatic Approval: Handles ERC20 approvals for precompile tokens
- Stake Calculation: Real-time stake calculation from contract settings
- MetaMask Integration: Automatic wallet detection and connection
- Network Switching: Seamless switching between supported networks
- Balance Loading: Real-time token balance updates
- Form Validation: Comprehensive input validation
- Error Handling: User-friendly error messages
- Responsive Design: Mobile-first responsive layout
src/
βββ components/ # React components
β βββ Header.js # Navigation and wallet connection
β βββ BridgeForm.js # Main bridge interface
βββ contexts/ # React contexts
β βββ Web3Context.js # Web3 state management
βββ config/ # Configuration files
β βββ networks.js # Network and contract configuration
βββ contracts/ # Contract ABIs
β βββ abi.js # Contract interfaces
βββ utils/ # Utility functions
β βββ web3.js # Web3 helper functions
βββ App.js # Main application component
βββ index.js # Application entry point
βββ index.css # Global styles
pnpm devorpnpm start: Start development serverpnpm build: Build for productionpnpm test: Run testspnpm eject: Eject from Create React Apppnpm lint: Run ESLintpnpm lint:fix: Fix ESLint issues automatically
The app uses Tailwind CSS with custom components.
- MetaMask Only: Only MetaMask is supported for security
- Network Validation: All networks are validated before use
- Address Validation: All addresses are validated using ethers.js
- Smart Contracts: The contracts are open source and available for review (evm v1.1, evm v1-substrate)
Enable debug logging by setting:
localStorage.setItem('debug', 'true');- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
This is an open source free software. Use it at your own risk.