Esc

View as Markdownllms.txt

Transfer

Initiate a transfer of native, ERC-20, ERC-721 or ERC-1155 tokens. Shows the user a summary of the transfer to approve.

If the user doesn't have enough funds or gas to complete the transfer, they are given the opportunity to ramp before continuing.

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

const result = await mega.transfer({
    type: 'erc20',
    to: '0xFD8D73c93385271d06138FA0Ff6E9c639C3Bd8b0',
    contractAddress: '0x2715b6d04b6a0AB227631019899282a585Be410F',
    amount: parseUnits('1', 18).toString(),
});

if (result.status === 'approved') {
    console.log('Transaction hash:', result.receipt?.hash);
}
Runs on testnet with your wallet
ts
interface TransferRequest {
    type: 'native' | 'erc20' | 'erc721' | 'erc1155';
    to: `0x${string}`;
    amount: string;
    contractAddress?: string;
    tokenId?: number;
    sponsor?: boolean;
}

interface TransactionResult {
    status: 'approved' | 'cancelled' | 'error';
    receipt?: TransactionReceipt;
    receipts?: TransactionReceipt[];
    error?: string;
}