> 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/wallet/examples.md).

# Examples

Implementation starting points covering the most common MOSS flows. They assume production-minded defaults: explicit user intent, restrictive permission scopes, and backend-controlled trust decisions. Adapt to your own app state, analytics, and error handling before shipping.

## Vanilla TS Bootstrap

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

await mega.initialise({ network: 'mainnet', logging: 'error' });

const status = await mega.status();
if (status.status !== 'connected') {
  await mega.connect();
}
```

## Sponsored Gas Bootstrap

```ts
await mega.initialise({
  network: 'mainnet',
  logging: 'error',
  sponsorUrl: 'https://api.example.com/paymaster/approve',
  sponsorMode: 'app-only',
  sponsorToken: 'native',
});
```

## React Bootstrap

```tsx
import { MegaProvider } from '@megaeth-labs/wallet-sdk-react';

export function Root() {
  return (
    <MegaProvider config={{ network: 'mainnet', logging: 'error' }}>
      <App />
    </MegaProvider>
  );
}
```

## Connect and Sign

```ts
await mega.connect();
const signed = await mega.signMessage('Sign in to Example App');
```

## Transfer with Permissions-Aware UX

```ts
const permissionState = await mega.getPermissions();

if (!permissionState?.permissions) {
  await mega.grantPermissions({
    permissions: {
      expiry: 10 * 60,
      permissions: {
        calls: [{ to: '0xTokenContractAddress', signature: 'approve(address,uint256)' }],
        spend: [{ limit: 1000000000000000n, period: 'day' }],
      },
    },
  });
}

await mega.transfer({
  amount: '500000000000000000',
  to: '0xabc123abc123abc123abc123abc123abc123abcd',
  type: 'native',
});
```

## Contract Interaction

```ts
const name = await mega.getFromContract<string>({
  address: '0xfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed',
  abi: erc20Abi,
  functionName: 'name',
  args: [],
});

await mega.callContract({
  address: '0xfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed',
  abi: erc20Abi,
  functionName: 'approve',
  args: ['0xspender0000000000000000000000000000000000', '1000000'],
});
```

## Server-Side Verification

```ts
import {
  getMessageToSign,
  type MessageToConfirm,
  verifySignature,
} from '@megaeth-labs/wallet-server-verify';

const walletAddress = '0xYourWalletAddress';
const challenge = getMessageToSign(config, walletAddress);

const signedMessage: MessageToConfirm = {
  ...challenge,
  signature: '0xSignature',
};

await verifySignature(config, signedMessage);
```


---

# 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:

```
GET https://docs.megaeth.com/moss-docs/wallet/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
