# 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](https://moss.megaeth.com/developers/concepts/ramps) before
continuing.

> [!NOTE]
> Paying for something? Try [checkout](https://moss.megaeth.com/developers/methods/sending-funds/checkout) instead.

```ts title="Pure JS"
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);
}
```

```tsx title="React"
import { useTransfer } from '@megaeth-labs/wallet-sdk-react';
import { parseUnits } from 'viem';

export default function SendTokenButton() {
    const { mutate: transfer, isPending, data } = useTransfer();

    return (
        <>
            <button
                disabled={isPending}
                onClick={() =>
                    transfer({
                        type: 'erc20',
                        to: '0xFD8D73c93385271d06138FA0Ff6E9c639C3Bd8b0',
                        contractAddress: '0x2715b6d04b6a0AB227631019899282a585Be410F',
                        amount: parseUnits('1', 18).toString(),
                    })
                }
            >
                Send 1 token
            </button>
            {data?.status === 'approved' && <p>Sent: {data.receipt?.hash}</p>}
        </>
    );
}
```

```tsx title="Wagmi"
import type { MegaWalletProvider } from '@megaeth-labs/wallet-wagmi-connector';
import { parseUnits } from 'viem';
import { useAccount } from 'wagmi';

export default function SendTokenButton() {
    const { connector } = useAccount();

    async function transfer() {
        const provider = (await connector?.getProvider()) as MegaWalletProvider;

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

        console.log('Transaction hash:', receipt?.hash);
    }

    return (
        <button onClick={transfer} disabled={!connector}>
            Send 1 token
        </button>
    );
}
```

```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;
}
```
