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

mega.transfer()

Send native ETH, ERC-20, ERC-721, or ERC-1155 transfers from the connected wallet. Returns a TransactionResult with status, receipt, and optional error. The wallet always prompts for transfers — for silent delegated execution, use callContract() with matching permissions.

Signature

mega.transfer(request: TransferRequest): Promise<TransactionResult>

Parameters

Field
Type
Required
Notes

type

'native' / 'erc20' / 'erc721' / 'erc1155'

required

Asset type.

to

`0x${string}`

required

Recipient address.

amount

string

required

Wei (native) or smallest token unit.

contractAddress

string

optional

Required for ERC-20 / 721 / 1155.

tokenId

number

optional

Required for ERC-721 / 1155.

sponsor

boolean

optional

Request sponsorship in explicit mode — see Paymaster Guide.

Example

import { parseEther } from 'viem';

const result = await mega.transfer({
  type: 'native',
  to: '0xRecipientAddress',
  amount: parseEther('0.1').toString(),
});

if (result.status === 'approved') {
  console.log(result.receipt?.hash);
} else if (result.status === 'cancelled') {
  console.log('User cancelled transfer');
} else {
  console.error(result.error);
}

Response

Status
Meaning
Action

approved

Transaction confirmed

Use result.receipt?.hash

cancelled

User rejected in-wallet confirmation

Treat as neutral, reset UI

error

Operational failure (RPC, balance, contract)

Inspect result.error, show retry

silentHasUsedFallback is set to true when silent: true was attempted on a callContract() call but fell back to UI approval — typically because the matching session permission had expired and silentUIApproveFallback: true triggered the fallback path.

Notes

  • Show amount, asset, and destination before opening the wallet.

  • If the wallet is disconnected, prompt connect() first.

Last updated