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)
- BSC (Mainnet & Testnet)
- 3DPass (Mainnet & Testnet)
- ETH (Native)
- USDT
- USDC
- BNB (Native)
- BUSD
- USDT
- P3D (Native, ERC20 Precompile at
0x0802
) - wUSDT (Wrapped USDT, ERC20 Precompile at
0xde
) - wUSDC (Wrapped USDC, ERC20 Precompile at
0x6f
) - wBUSD (Wrapped BUSD, ERC20 Precompile at
0x14D
)
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/npm/yarn
- MetaMask browser extension
- Access to supported networks in MetaMask
-
Clone the repository
git clone <repository-url> cd bridge-frontend
-
Install dependencies
# Using pnpm (recommended) pnpm install # Or using npm npm install # Or using yarn yarn install
-
Configure networks (Optional) Edit
src/config/networks.js
to update RPC URLs and contract addresses for your deployment. -
Start the development server
# Using pnpm pnpm dev # or pnpm start # Or using npm npm start # Or using yarn yarn 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: {
exportFactory: '0x...',
importFactory: '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 dev
orpnpm 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:
- Custom Colors: Dark theme with primary, accent, and utility colors
- Components: Pre-built button, input, and card components
- Animations: Framer Motion for smooth transitions
- Responsive: Mobile-first responsive design
- 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
- Amount Validation: All amounts are validated and checked against balances
- Stake Protection: Stakes protect against fraudulent transfers
-
MetaMask Not Detected
- Ensure MetaMask is installed and unlocked
- Refresh the page and try again
-
Network Not Supported
- Add the network to MetaMask manually
- Check network configuration in
networks.js
-
Insufficient Balance
- Check your token balance
- Remember to account for gas fees and stake requirements
-
Transaction Fails
- Check gas settings in MetaMask
- Ensure sufficient balance for gas fees
- Verify network connection
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.
For support and questions:
- Check the troubleshooting section
- Review the documentation
- Open an issue on GitHub
- Advanced settings panel
- Multi-language support
- Dark/light theme toggle
- Mobile app version
- Additional network support