Skip to content

Connect a website to M5wallet

M5wallet works with any site that already supports browser wallets. Nothing special is needed for the browser extension.

If you would rather not write the wiring yourself, M5wallet hosts a small script. It connects through the extension on a computer, opens your page inside M5wallet on a phone, and opens the wallet itself in a window for a visitor who has neither:

<script src="https://m5wallet.com/embed/m5-connect.js"></script>
<div id="m5-connect"></div>
<script>
M5Connect.mount('#m5-connect', {
onConnect: ({ address, provider }) => {
// `provider` is a normal EIP-1193 provider: use it with viem, ethers,
// or raw requests as below.
console.log('connected', address);
},
});
</script>

After connecting it asks the wallet for BNB Smart Chain, where M5L lives (pass chain: false to skip that). For your own button, the same script also gives you M5Connect.detect(), M5Connect.connect(), M5Connect.openInApp() and M5Connect.switchToBnbChain(provider).

A working example, including reading an M5L balance, is at m5wallet.com/embed/demo.html.

The script has no dependencies and never touches keys: every signature is approved in the wallet, as with any other website.

When someone has the M5wallet extension, every page they open gets:

  • an EIP-6963 announcement with name M5wallet, the M5wallet icon and the identifier so.onekey.app.wallet. Connect buttons built with wagmi, RainbowKit, ConnectKit, Web3Modal/AppKit or plain EIP-6963 list it automatically, under the name M5wallet.
  • window.ethereum — the EIP-1193 provider. It reports isMetaMask: true for compatibility with older sites, and isOneKey: true.
  • window.$onekey, window.solana and window.onekeyTonWallet for wallet-specific access.

M5wallet is built on OneKey’s open-source wallet, so the identifier stays so.onekey.app.wallet and existing integrations keep working. Detect M5wallet by the announced name:

const wallets = [];
window.addEventListener('eip6963:announceProvider', (e) => wallets.push(e.detail));
window.dispatchEvent(new Event('eip6963:requestProvider'));
// after a tick
const m5 = wallets.find((w) => w.info.name === 'M5wallet');
const [address] = await m5.provider.request({ method: 'eth_requestAccounts' });

Ask for BNB Smart Chain (chain id 56) before a transaction:

await m5.provider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x38' }],
});

The embedded wallet — for visitors with nothing installed

Section titled “The embedded wallet — for visitors with nothing installed”

Someone with no extension and no app can still connect. The button opens M5wallet itself in a small window on app.m5wallet.com, where they create or unlock a wallet and approve each request — no install, nothing to download. This is what the button above already does; pass embedded: false to send them to the download page instead.

<script src="https://m5wallet.com/embed/m5-connect.js"></script>
<div id="m5-connect"></div>
<script>
M5Connect.mount('#m5-connect', {
// embedded: false, // opt out: send them to the download page instead
onConnect: ({ address, provider }) => console.log('connected', address),
});
</script>

The order is always the same: the extension when it is there, the app on a phone, and the window only as the last resort. To open it yourself, from a click handler:

const { address, provider } = await M5Connect.connectEmbedded();
const hash = await provider.request({
method: 'eth_sendTransaction',
params: [{ from: address, to: '0x…', value: '0x…' }],
});

provider is an EIP-1193 provider like any other, so request works the same way — pass it to viem or ethers if you prefer.

What your page can and cannot see. The wallet runs on our origin, not yours. Keys, the recovery phrase and the password never leave that window, and your page cannot read them — a browser will not let it. Your page receives what the person approves: their address, signatures, and transaction hashes.

Every request names your website on the approval screen, and only these are accepted: accounts and chain id, reading the chain (eth_call, balances, receipts), eth_sendTransaction, personal_sign, eth_signTypedData_v4, and the wallet_* chain and permission calls. Anything else is refused.

Two things to know before you ship it:

  • It is a popup window, so call it from a click. Browsers block a window opened any other way, and the script reports M5_POPUP_BLOCKED.
  • Events are not delivered yet. provider.on('accountsChanged', …) accepts a listener but nothing calls it; ask for eth_accounts and eth_chainId when you need them.

Someone who already has a wallet in that browser gets it back when they return: the window remembers, because it is the same M5wallet web app they would use at app.m5wallet.com. If they lose the device, the wallet’s own backup — the recovery phrase, or their Google sign-in — is what restores it, exactly as in the app.

Two ways, both working today:

  1. The wallet’s own browser. In M5wallet, open Browser and enter your address. Your site then sees the same provider as in the extension, so the same Connect button works.
  2. WalletConnect. Show a WalletConnect QR code on your site. In M5wallet, open the scanner (top of the Wallet page) and scan it.

M5wallet is not in WalletConnect’s public wallet directory, so it does not appear by name in a WalletConnect modal’s wallet list. Scanning the QR code from the wallet works regardless.

The desktop app has the same Browser tab as the extension, with the same provider, and it also accepts WalletConnect.

app.m5wallet.com has no built-in browser, so a site cannot inject into it. Visitors on a computer should use the extension, or the embedded wallet described above; on a phone, the app’s browser.

  • Network: BNB Smart Chain, chain id 56 (0x38).
  • Contract: 0x8d668f33621b5c664f29de0a7f5336947fcba98e
  • Symbol and decimals: M5L, 18.

Every BNB Chain account in M5wallet already lists M5L, so a buyer sees the balance without adding the token by hand.

m5-wallet://dapp?url=https://your-site.example opens your site in M5wallet’s own browser, where the wallet is injected — so the page that opens can ask to connect straight away. It works in the phone app and in the desktop app, which registers the same link. Put it behind a button:

<a href="m5-wallet://dapp?url=https://your-site.example">Open in M5wallet</a>
  • The app opens the link only when it is https, on a public address, with no credentials in it and not a file download.
  • Nothing happens if M5wallet is not installed, so offer the download page as well.
  • This needs M5wallet 6.4.2 or newer.

m5-wallet://webview?url=https://example.com is the other one: it opens an https page in a plain viewer with no wallet in it, for information only.