Connect any website, decentralized app, or portal to Canton Network in minutes with our lightweight, non-custodial JavaScript SDK.
Ultralight (< 5KB), zero external baggage. Embed anywhere via CDN script tag or modern npm bundle.
Fully compliant with standard Canton SPLICE wallet JSON-RPC specifications for secure message signing.
Effortlessly integrate with React, Vue, Next.js, Angular, Svelte, or plain Vanilla JavaScript.
Choose your preferred setup method and get your dApp connected in under 3 minutes.
<!-- 1. Include MahaWallet dApp SDK -->
<script src="https://mahawallet.xyz/static/js/mahawallet-sdk.js"></script>
<button id="connectBtn">Connect MahaWallet</button>
<script>
document.getElementById('connectBtn').addEventListener('click', async () => {
try {
// Check if user has extension installed
const installed = await MahaWallet.isInstalled();
if (!installed) {
alert("Please install MahaWallet from https://mahawallet.xyz");
return;
}
// Prompt connect approval
const wallet = await MahaWallet.connect();
console.log("Connected Successfully!", wallet);
alert("Connected Party ID: " + wallet.partyId);
} catch (err) {
console.error("Connection failed:", err);
}
});
</script>
// Install via npm or load from your local package
import { MahaWallet } from '@mahawallet/sdk';
async function initDApp() {
// 1. Check readiness
if (!(await MahaWallet.isInstalled())) {
console.warn("MahaWallet is not detected.");
return;
}
// 2. Request connection
const session = await MahaWallet.connect();
console.log("Primary Party ID:", session.partyId);
console.log("Network:", session.networkId);
// 3. Listen to disconnect events
MahaWallet.on('disconnect', () => {
console.log("User disconnected their session.");
});
}
import React, { useState } from 'react';
import { MahaWallet } from '@mahawallet/sdk';
export function ConnectWalletButton() {
const [partyId, setPartyId] = useState<string | null>(null);
const [connecting, setConnecting] = useState(false);
const handleConnect = async () => {
try {
setConnecting(true);
const res = await MahaWallet.connect();
setPartyId(res.partyId);
} catch (err: any) {
alert(err?.message || "Failed to connect wallet");
} finally {
setConnecting(false);
}
};
const handleDisconnect = async () => {
await MahaWallet.disconnect();
setPartyId(null);
};
if (partyId) {
return (
<div className="d-flex align-items-center gap-2">
<span>{partyId.slice(0, 10)}...{partyId.slice(-4)}</span>
<button onClick={handleDisconnect}>Disconnect</button>
</div>
);
}
return (
<button onClick={handleConnect} disabled={connecting}>
{connecting ? 'Connecting...' : 'Connect MahaWallet'}
</button>
);
}
Test the real MahaWallet SDK methods in real-time with your installed extension.
// Click any button on the left to execute SDK methods. // Make sure MahaWallet extension is installed.
Comprehensive documentation for all methods provided by the SDK.
| Method | Parameters | Return Type | Description |
|---|---|---|---|
isInstalled(timeoutMs?) |
timeoutMs: number (opt) |
Promise<boolean> |
Detects if the MahaWallet browser extension is active. |
connect(timeoutMs?) |
timeoutMs: number (opt) |
Promise<ConnectResult> |
Prompts wallet connection and returns primary party ID. |
disconnect() |
none |
Promise<boolean> |
Clears session and revokes dApp connection state. |
getAccount() |
none |
Promise<Account | null> |
Retrieves active primary account party ID and metadata. |
listAccounts() |
none |
Promise<Account[]> |
Lists all authorized accounts inside the user's wallet. |
signMessage(message) |
message: string |
Promise<Signature> |
Requests cryptographic signature for an arbitrary string. |
request(method, params?) |
method: string, params: object |
Promise<any> |
Sends raw CIP-103 JSON-RPC request to MahaWallet. |
on(event, callback) |
event: string, fn: function |
unsubscribeFn |
Subscribes to connect, disconnect, etc. |