Initialise
Before using the wallet, the initialise function must be called. This embeds the iFrame, establishes the
communication channel and checks for any existing connections to your app.
import { mega } from '@megaeth-labs/wallet-sdk';
const status = await mega.initialise({
network: 'testnet'
});import { MegaProvider } from '@megaeth-labs/wallet-sdk-react';
export default function App() {
return (
<MegaProvider config={{ network: 'testnet' }}>
{/* ...your app */}
</MegaProvider>
);
}import { mossWallet } from '@megaeth-labs/wallet-wagmi-connector';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { megaethTestnet } from 'viem/chains';
import { createConfig, http, WagmiProvider } from 'wagmi';
const config = createConfig({
chains: [megaethTestnet],
connectors: [mossWallet({ network: 'testnet' })],
transports: {
[megaethTestnet.id]: http(),
},
});
const queryClient = new QueryClient();
export default function App() {
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
{/* ...your app */}
</QueryClientProvider>
</WagmiProvider>
);
}The following options are available for the config object:
ts
interface Config {
network: 'mainnet' | 'testnet';
logging?: 'debug' | 'info' | 'warn' | 'error';
sponsorUrl?: string;
sponsorMode?: 'everything' | 'app-only' | 'explicit';
sponsorToken?: 'native' | 'usdm';
}