> For the complete documentation index, see [llms.txt](https://docs.megaeth.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.megaeth.com/moss-docs/methods/methods.md).

# Method reference

Complete reference for `@megaeth-labs/wallet-sdk` — 19 methods covering connection, signing, transactions, contract calls, Smart Approvals, balances, and deposits. Zero framework dependencies; works in any browser environment.

The SDK embeds `https://account.megaeth.com` in a hidden iframe, communicates via Penpal, and exposes one object: `mega`.

```bash
npm install @megaeth-labs/wallet-sdk
```

Typical lifecycle: `initialise → connect → [transfer / callContract / signMessage / grantPermissions / send / swap] → disconnect`.

## Setup & Connection

| Method                                                                             | Purpose                                                           |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [`mega.initialise(config)`](/moss-docs/methods/methods/initialise.md)              | Create the wallet iframe and bridge, wait for ready.              |
| [`mega.connect()`](/moss-docs/methods/methods/connect.md)                          | Prompt the user to authenticate; resolves with connection status. |
| [`mega.disconnect()`](/moss-docs/methods/methods/disconnect.md)                    | Terminate the active wallet session.                              |
| [`mega.status()`](/moss-docs/methods/methods/status.md)                            | Read current connection state without prompting.                  |
| [`mega.open()`](/moss-docs/methods/methods/open.md)                                | Show the wallet UI overlay without an explicit action.            |
| [`mega.events.onStatusChange(cb)`](/moss-docs/methods/methods/on-status-change.md) | Subscribe to connection state changes.                            |

## Transactions

| Method                                                                             | Purpose                                            |
| ---------------------------------------------------------------------------------- | -------------------------------------------------- |
| [`mega.transfer(request)`](/moss-docs/methods/methods/transfer.md)                 | Send native or ERC-20/721/1155 transfers.          |
| [`mega.callContract(request)`](/moss-docs/methods/methods/call-contract.md)        | Execute contract write functions, single or batch. |
| [`mega.getFromContract(request)`](/moss-docs/methods/methods/get-from-contract.md) | Read contract state.                               |

## Signing

| Method                                                                    | Purpose                                                 |
| ------------------------------------------------------------------------- | ------------------------------------------------------- |
| [`mega.signMessage(message)`](/moss-docs/methods/methods/sign-message.md) | Sign an arbitrary text payload.                         |
| [`mega.signData(request)`](/moss-docs/methods/methods/sign-data.md)       | Sign structured (EIP-712) data.                         |
| [`mega.authenticate()`](/moss-docs/methods/methods/authenticate.md)       | Request a MOSS-issued JWT for backend session exchange. |

## Smart Approvals (Policy Engine)

| Method                                                                              | Purpose                                                  |
| ----------------------------------------------------------------------------------- | -------------------------------------------------------- |
| [`mega.grantPermissions(request)`](/moss-docs/methods/methods/grant-permissions.md) | Grant scoped delegated permissions for silent execution. |
| [`mega.revokePermissions()`](/moss-docs/methods/methods/revoke-permissions.md)      | Revoke all active delegated permissions.                 |
| [`mega.getPermissions(address?)`](/moss-docs/methods/methods/get-permissions.md)    | Read active permission grants.                           |

For the conceptual model, see [Smart Approvals (Policy Engine)](/moss-docs/core-sdk/permissions.md).

## Wallet

| Method                                                             | Purpose                               |
| ------------------------------------------------------------------ | ------------------------------------- |
| [`mega.deposit()`](/moss-docs/methods/methods/deposit.md)          | Open the built-in deposit/funding UI. |
| [`mega.balances(request)`](/moss-docs/methods/methods/balances.md) | Fetch wallet token balances.          |
| [`mega.send(request)`](/moss-docs/methods/methods/send.md)         | Open the wallet-managed send flow.    |
| [`mega.swap(request)`](/moss-docs/methods/methods/swap.md)         | Open the wallet-managed swap flow.    |

## Shared Types

```typescript
type ConnectionStatus = {
  status: 'connected' | 'disconnected' | 'cancelled';
  address?: `0x${string}`;
  network: 'mainnet' | 'testnet';
};

type TransactionResult = {
  status: 'approved' | 'cancelled' | 'error';
  receipt?: {
    hash: `0x${string}`;
    blockHash: string;
    blockNumber: number;
    chainId: number;
    gasUsed: number;
    logs: { address: `0x${string}`; data: `0x${string}`; topics: string[] }[];
    status: string;
    transactionHash: `0x${string}`;
  };
  receipts?: TransactionResult['receipt'][];  // populated for batch callContract
  error?: string;
  silentHasUsedFallback?: boolean;  // true when silent fell back to UI approval
};
```

Per-method response shapes (e.g., `SignMessageResponse`, `OwnedTokenResponse`, `Permission`) live on their respective method pages.

## Cross-Cutting Guides

* [SDK installation](/moss-docs/core-sdk/installation.md) — package install, import surface, what you get.
* [Connection lifecycle](/moss-docs/core-sdk/lifecycle.md) — the recommended setup → connect → disconnect flow.
* [Smart Approvals deep-guide](/moss-docs/core-sdk/permissions.md) — when to grant, how to scope, revocation patterns.
* [Security model](/moss-docs/core-sdk/security.md) — iframe model, trust boundaries, what stays server-side.
* [Troubleshooting](/moss-docs/core-sdk/error-handling.md) — common errors and triage steps.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.megaeth.com/moss-docs/methods/methods.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
