API Interactive Demo
Test MetaC wallet integration in real-time
⏳
Checking for MetaC...
Please wait while we detect the MetaC extension.
1. Connect Wallet
Connect to the active MetaC account. This is the first step for any DApp integration.
JavaScript
// Connect to MetaC wallet
const account = await window.metacwallet.connect();
console.log('Connected address:', account.address);
// Check if connected
const isConnected = await window.metacwallet.isConnected();
// Disconnect
await window.metacwallet.disconnect();
2. Get Account Information
Retrieve address, public key, and extended public key from the connected wallet.
JavaScript
// Get wallet address
const address = await window.metacwallet.getAddress();
// Get public key
const publicKey = await window.metacwallet.getPublicKey();
// Get extended public key
const xPublicKey = await window.metacwallet.getXPublicKey();
3. Check Balance
Query the current balance of the connected wallet.
JavaScript
// Get balance information
const balance = await window.metacwallet.getBalance();
console.log('Confirmed:', balance.confirmed / 100000000);
console.log('Unconfirmed:', balance.unconfirmed / 100000000);
console.log('Total:', balance.total / 100000000);
4. Network Management
Get current network and switch between mainnet and testnet.
JavaScript
// Get current network
const networkInfo = await window.metacwallet.getNetwork();
console.log('Current network:', networkInfo.network);
// Switch network (mainnet ↔ testnet)
const result = await window.metacwallet.switchNetwork();
console.log('Switched to:', result.network);
5. Listen to Events
Subscribe to wallet events like account changes and network switches.
JavaScript
// Listen for account changes
window.metacwallet.on('accountsChanged', (account) => {
console.log('Account changed:', account);
});
// Listen for network changes
window.metacwallet.on('networkChanged', (network) => {
console.log('Network changed to:', network);
});
// Remove event listeners
window.metacwallet.removeListener('accountsChanged');
window.metacwallet.removeListener('networkChanged');
Complete API Reference
🔐 Account Management
connect()- Connect to walletdisconnect()- Disconnect from walletisConnected()- Check connection statusgetAddress()- Get wallet addressgetPublicKey()- Get public keygetXPublicKey()- Get extended public key
💰 Balance & Transactions
getBalance()- Get native token balancetransfer(tasks, broadcast?)- Transfer assetssignTransaction(transaction)- Sign a transactionsignTransactions(transactions)- Sign multiple transactionspreviewTransaction(transaction)- Preview transaction ID
🌐 Network
getNetwork()- Get current networkswitchNetwork()- Switch between mainnet/testnet
🎨 Tokens & NFTs
token.getBalance(genesis?, codehash?)- Get token balancetoken.list()- List all tokensnft.list()- List all NFTsnft.transfer()- Transfer NFT
📡 Events
on('accountsChanged', callback)- Listen for account changeson('networkChanged', callback)- Listen for network changesremoveListener(eventName)- Remove event listener