Multi-chain Wallet Development
Multi-chain wallet is not just "connect several networks". It's complex system handling fundamentally different blockchain architectures: EVM-compatible chains (Ethereum, Arbitrum, Polygon, BSC), EVM-incompatible (Solana, Sui, Aptos), Bitcoin with UTXO model, Cosmos ecosystem with IBC. Each has own cryptography, transaction format, fee mechanism, and account model.
Key Choice: Key Derivation
HD Wallet and BIP-44 Standard
All modern multi-chain wallets built on BIP-32/BIP-39/BIP-44 standards. One seed phrase (12-24 words) → one master key → tree of child keys for each network.
BIP-44 derivation path: m / purpose' / coin_type' / account' / change / index
import { HDNodeWallet, Mnemonic } from 'ethers';
import { derivePath } from 'ed25519-hd-key';
import * as bip39 from 'bip39';
// Generate seed phrase
const mnemonic = Mnemonic.fromEntropy(crypto.getRandomValues(new Uint8Array(16)));
const seed = await bip39.mnemonicToSeed(mnemonic.phrase);
// EVM chains (Ethereum, Arbitrum, Polygon) — secp256k1, coin_type = 60
const evmWallet = HDNodeWallet.fromSeed(seed).derivePath("m/44'/60'/0'/0/0");
console.log('EVM address:', evmWallet.address);
// Solana — ed25519, coin_type = 501
const solanaPath = "m/44'/501'/0'/0'";
const { key: solanaPrivKey } = derivePath(solanaPath, seed.toString('hex'));
// ... create Solana Keypair
Different Curves for Different Chains
| Chain | Curve | BIP-44 coin_type |
|---|---|---|
| Ethereum and EVM | secp256k1 | 60 |
| Bitcoin | secp256k1 | 0 |
| Solana | Ed25519 | 501 |
| Cosmos/ATOM | secp256k1 | 118 |
| Sui | Ed25519 | 784 |
| Near | Ed25519 | 397 |
Can't use one library for all chains. EVM — ethers.js/viem, Solana — @solana/web3.js, Cosmos — cosmjs, Bitcoin — bitcoinjs-lib. Architecture must account for this.
Wallet Architecture
Chain Abstraction Layer
interface ChainAdapter {
chainId: string;
chainName: string;
getAddress(publicKey: Uint8Array): string;
getBalance(address: string): Promise<bigint>;
buildTransaction(params: TxParams): Promise<UnsignedTx>;
signTransaction(tx: UnsignedTx, privateKey: Uint8Array): Promise<SignedTx>;
broadcastTransaction(tx: SignedTx): Promise<string>;
getTransactionStatus(txHash: string): Promise<TxStatus>;
estimateFee(tx: UnsignedTx): Promise<FeeEstimate>;
}
// EVM Implementation
class EVMAdapter implements ChainAdapter {
private client: PublicClient;
constructor(rpcUrl: string, public chainId: string, public chainName: string) {
this.client = createPublicClient({ transport: http(rpcUrl) });
}
async getBalance(address: string): Promise<bigint> {
return this.client.getBalance({ address: address as `0x${string}` });
}
async buildTransaction(params: TxParams): Promise<UnsignedTx> {
const nonce = await this.client.getTransactionCount({ address: params.from as `0x${string}` });
const feeData = await this.client.estimateFeesPerGas();
return {
to: params.to,
value: params.value ?? 0n,
data: params.data ?? '0x',
nonce,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
chainId: BigInt(this.chainId),
};
}
}
Multi-chain State Management
Wallet works with 10+ networks simultaneously. Balances, transactions, pending operations — for each network independently. Poor implementation: sequential requests — slow. Good: parallel requests with per-chain state.
async function loadAllBalances(
adapters: ChainAdapter[],
addresses: Map<string, string>
): Promise<Map<string, bigint>> {
const results = await Promise.allSettled(
adapters.map(adapter => {
const address = addresses.get(adapter.chainId);
if (!address) return Promise.resolve([adapter.chainId, 0n] as [string, bigint]);
return adapter.getBalance(address)
.then(balance => [adapter.chainId, balance] as [string, bigint]);
})
);
const balances = new Map<string, bigint>();
for (const result of results) {
if (result.status === 'fulfilled') {
const [chainId, balance] = result.value;
balances.set(chainId, balance);
}
}
return balances;
}
Security: Private Key Storage
Mobile Wallet
iOS: Secure Enclave for key generation and storage. Private key never leaves chip physically. Transaction signing happens inside Enclave, result — only signed transaction.
Limitation: Secure Enclave supports only P-256 (secp256r1), not secp256k1 (Ethereum). Solution: store seed encrypted in iOS Keychain with biometry, decrypt only for signing in protected memory.
Android: StrongBox (if hardware supported) or Android Keystore. Same limitations — HSM on Android doesn't support secp256k1 either.
// iOS: seed storage in Secure Enclave-protected Keychain
func storeSeed(_ seed: Data) throws {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: "wallet_seed",
kSecValueData as String: seed,
kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
]
let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else { throw KeychainError.unhandledError(status) }
}
Web/Extension Wallet
Most vulnerable environment. Main risks: malicious extensions access same page, XSS in dApp can try to access extension API.
Separation: background + content script + popup:
- Private keys stored only in background service worker
- Content script injected in pages (provides window.ethereum), no key access
- All key operations — messages to background via
chrome.runtime.sendMessage
Encryption: seed encrypted with user password via scrypt/argon2 + AES-256-GCM. In memory only when unlocked, auto-cleared after N minutes.
Fee Estimation in Multi-chain Context
Each chain has own fee model:
EVM with EIP-1559: baseFee + priorityFee. Protocol-set baseFee, priorityFee — tip for validator. Monitor gas price in real-time, recommend slow/average/fast.
async function getEVMFeeOptions(client: PublicClient): Promise<FeeOptions> {
const [block, feeHistory] = await Promise.all([
client.getBlock(),
client.getFeeHistory({ blockCount: 5, rewardPercentiles: [25, 50, 75] })
]);
const baseFee = block.baseFeePerGas ?? 0n;
return {
slow: { maxFeePerGas: baseFee * 110n / 100n, maxPriorityFeePerGas: ... },
average: { maxFeePerGas: baseFee * 120n / 100n, maxPriorityFeePerGas: ... },
fast: { maxFeePerGas: baseFee * 150n / 100n, maxPriorityFeePerGas: ... },
};
}
Solana: fee = lamports per signature × signature count. Relatively stable. Account priority fees (compute units) at high load.
Bitcoin: fee = satoshis per virtual byte. Depends on UTXO set size (more inputs → more bytes → costlier). Need UTXO selection algorithm.
Token Management and NFT Support
Token Discovery
Users shouldn't manually add each token. Automatic discovery:
EVM: Etherscan/Covalent Token API or scan Transfer events to user address. TokenList standard (Uniswap) for whitelisted tokens.
Solana: getParsedTokenAccountsByOwner — returns all SPL tokens in one RPC call.
NFT Support
ERC-721 and ERC-1155 on EVM: Alchemy NFT API or Moralis for metadata aggregation. IPFS loading with fallback (many NFTs have broken IPFS links).
async function getUserNFTs(address: string, chainId: number) {
const alchemy = new Alchemy({
apiKey: process.env.ALCHEMY_KEY,
network: chainIdToNetwork(chainId),
});
const nfts = await alchemy.nft.getNftsForOwner(address);
return nfts.ownedNfts.map(nft => ({
contractAddress: nft.contract.address,
tokenId: nft.tokenId,
name: nft.name,
imageUrl: nft.image.cachedUrl,
collection: nft.contract.name,
}));
}
WalletConnect and dApp Integration
WalletConnect v2 — standard protocol for wallet-to-dApp connection. Sign API for signing, Auth API for authentication.
import { Web3Wallet } from '@walletconnect/web3wallet';
const web3wallet = await Web3Wallet.init({
core: new Core({ projectId: process.env.WALLETCONNECT_PROJECT_ID }),
metadata: {
name: 'My Wallet',
description: 'Multichain Wallet',
url: 'https://mywallet.io',
icons: ['https://mywallet.io/icon.png'],
},
});
web3wallet.on('session_request', async (event) => {
const { topic, params } = event;
const { request } = params;
if (request.method === 'eth_sendTransaction') {
const confirmed = await showTransactionConfirmation(request.params[0]);
if (confirmed) {
const signedTx = await signEVMTransaction(request.params[0]);
await web3wallet.respondSessionRequest({
topic,
response: { id: event.id, jsonrpc: '2.0', result: signedTx }
});
}
}
});
Stack and Development Timeline
| Component | Technologies | Timeline |
|---|---|---|
| Core HD wallet | bip39 + ethers.js + @solana/web3.js | 2-3 weeks |
| EVM multi-chain | viem, 10+ networks | 2-3 weeks |
| Solana integration | @solana/web3.js + Metaplex | 2 weeks |
| Mobile (RN) | React Native + Expo SecureStore | 4-6 weeks |
| Extension (Chrome) | MV3 + chrome.storage | 3-4 weeks |
| WalletConnect v2 | @walletconnect/web3wallet | 1-2 weeks |
| NFT + token discovery | Alchemy/Moralis API | 2-3 weeks |
| UI/UX (full) | React Native / React | 6-10 weeks |
Minimum production-ready multi-chain wallet (EVM + Solana, mobile-first) — 4-5 months. Adding Bitcoin (UTXO model) — another 4-6 weeks separately due to different architecture. Cosmos expansion — 3-4 weeks via cosmjs.
Security requires external audit before public release — wallet stores user keys directly, maximum risk.







