Connect
Trigger the connection flow from an action in your app.
import { mega } from '@megaeth-labs/wallet-sdk';
const { status, address } = await mega.connect();
if (status === 'connected') {
console.log('Connected:', address);
}import { useConnect, useStatus } from '@megaeth-labs/wallet-sdk-react';
export default function ConnectButton() {
const { status, address } = useStatus();
const { mutate: connect, isPending } = useConnect();
if (status === 'connected') return <p>Connected: {address}</p>;
return (
<button onClick={() => connect()} disabled={isPending}>
{isPending ? 'Connecting…' : 'Connect wallet'}
</button>
);
}import { useAccount, useConnect } from 'wagmi';
export default function ConnectButton() {
const { address, isConnected } = useAccount();
const { connect, connectors, isPending } = useConnect();
const connector = connectors.find((c) => c.id === 'mossWallet');
if (isConnected) return <p>Connected: {address}</p>;
return (
<button onClick={() => connector && connect({ connector })} disabled={!connector || isPending}>
{isPending ? 'Connecting…' : 'Connect wallet'}
</button>
);
}Runs on testnet with your wallet
ts
// Optional. With an address, the wallet shows "Continue as <address>" and asks
// for that account's passkey only.
interface ConnectRequest {
address?: `0x${string}`;
}
interface ConnectionStatus {
status: 'connected' | 'disconnected' | 'cancelled';
address?: `0x${string}`;
network: 'mainnet' | 'testnet';
}