<LinkTransfer />
Prex SDKを使用してERC20トークンのリンク送付を行う方法を説明します。
前提条件
- ウォレットが作成されていること
- 使用するERC20トークンが管理画面で設定されていること
コンポーネントの利用方法
リンク送付のリンクを作成する
有効期限付きのリンクを生成し、そのリンクを通じてトークンを送金します。
まず、送付用のURLを生成するために、makeURL
関数を作成します。
import { LinkTransferResponse } from "@prex0/uikit/link-transfer"
export const makeURL = (linkTransferResponse: LinkTransferResponse) => {
return `${window.location.origin}/receive?id=${encodeURIComponent(linkTransferResponse.id)}&s=${encodeURIComponent(linkTransferResponse.secret)}`
}
次に送付フォームを作成します。
import {
LinkTransfer,
LinkTransferAmountInput,
LinkTransferButton,
LinkTransferError,
LinkTransferTokenSelector,
LinkTransferShare,
} from '@prex0/uikit/link-transfer';
import { cn, pressable, text } from '@prex0/uikit/styles';
import { useState } from 'react';
import { makeURL } from './path/to/makeURL';
export const SendForm = ({token}: {token: Address}) => {
const [isSuccess, setIsSuccess] = useState(false);
return (
<div>
<LinkTransfer className="mt-4" token={token} amount='0' onSuccess={() => setIsSuccess(true)}>
<div className='flex justify-end'>
<LinkTransferTokenSelector />
</div>
<div className="mb-4">
<label className="block text-gray-700">Amount</label>
<LinkTransferAmountInput
className="w-full p-2 rounded-lg mt-1"
isMaxButton
/>
</div>
<LinkTransferError />
{
isSuccess ? (
<LinkTransferShare makeURL={makeURL} className='px-3'>
<button className={cn(pressable.inverse, text.label1, 'rounded-lg w-full h-10')}>Share</button>
</LinkTransferShare>
):(
<LinkTransferButton />
)
}
</LinkTransfer>
</div>
);
};