For the complete documentation index, see llms.txt. This page is also available as Markdown.

mega.initialise()

Create the wallet iframe, establish the Penpal bridge, and wait for the wallet host to signal readiness. Returns the initial connection status. Idempotent — call it once near app boot; calling it again is a no-op.

Signature

mega.initialise(config: Config): Promise<ConnectionStatus | undefined>

Parameters

Field
Type
Required
Notes

network

'mainnet' / 'testnet'

required

Selects wallet network; passed to the hosted wallet URL.

logging

'debug' / 'info' / 'warn' / 'error'

optional

SDK-side log verbosity.

devMode

boolean

optional

Switches wallet host from account.megaeth.com to localhost:4000.

debug

boolean

optional

Enables Penpal debug logging.

sponsorUrl

string

optional

Sponsorship approval endpoint URL.

sponsorMode

'everything' / 'app-only' / 'explicit'

optional

Sponsorship trigger mode. Default app-only. See Paymaster Guide.

sponsorToken

'native' / 'usdm'

optional

Sponsor fee token. Default native.

Example

import { mega } from '@megaeth-labs/wallet-sdk';

await mega.initialise({
  network: 'testnet',
  logging: 'info',
  debug: true,
  sponsorMode: 'app-only',
  sponsorToken: 'native',
});

const state = await mega.status();
console.log(state.status, state.address);

Response

The returned status reflects existing wallet state — initialisation guarantees bridge readiness, not user approval. Use connect() to prompt the user.

Notes

  • Call once near app boot. Calling again returns early without re-creating the iframe.

  • For SSR (Next.js): wrap in a 'use client' boundary or use the React SDK's MegaProvider. The iframe requires DOM access.

Last updated