A minimal demo application showcasing token transfers on Substrate chains using MetaMask and the Subeth ETH RPC adapter.
- Connect MetaMask wallet
- View account address, balance, and chain ID
- Send token transfers using Ethereum-style transactions
- Real-time balance updates
- Transaction status feedback
- MetaMask browser extension installed
- Subeth Adapter running on
http://localhost:8545 - Substrate Chain with funded accounts
-
Install dependencies:
npm install
-
Start development server:
npm run dev
-
Open browser: Navigate to
http://localhost:5173(or the port shown in terminal) -
Connect MetaMask:
- Click "Connect MetaMask"
- Approve the connection
- Your address and balance will be displayed
-
Send a transfer:
- Enter recipient address (0x...)
- Enter amount in smallest unit (e.g., 1000000000000)
- Click "Send Transaction"
- Approve in MetaMask
The app connects to a local Subeth adapter by default:
- RPC URL:
http://localhost:8545 - Chain ID: 42 (0x2A)
- Currency: UNIT (18 decimals)
To use a different network, modify the SUBETH_NETWORK constant in src/main.js.
cd chain
cargo run --releasecd adapter
cargo run --releasecd simple-dapp
npm run dev- Connection: MetaMask connects to the Subeth adapter at
http://localhost:8545 - Balance Query: App uses
eth_getBalanceto fetch account balance from Substrate chain - Transfer: User signs an Ethereum transaction with MetaMask
- Processing: Subeth adapter forwards the transaction to the Substrate chain (requires
evm-adapterpallet) - Confirmation: Transaction hash is returned and balance updates
connectWallet()- Request MetaMask connectionupdateAccountInfo()- Fetch balance and chain IDsendTransfer()- Submit transfer transactionformatBalance()- Convert wei to readable format
Transfers use standard Ethereum transaction structure:
{
from: currentAccount,
to: recipient,
value: valueHex, // Amount in hex
gas: '0x5208' // 21000 gas
}MetaMask not connecting:
- Ensure adapter is running on port 8545
- Check browser console for errors
Balance shows 0:
- Verify account is funded on the Substrate chain
- Check adapter is synced
Transaction fails:
- Ensure
evm-adapterpallet is in runtime - Check sufficient balance for transfer + gas
- Verify recipient address is valid
Wrong chain:
- Check MetaMask is connected to correct network
- Use "Switch Network" in MetaMask if needed
npm run buildOutputs to dist/ directory. Serve with any static file server.
- Vite - Build tool
- Vanilla JavaScript - No frameworks
- MetaMask - Wallet integration
- Subeth - ETH RPC adapter for Substrate