transfer
Transfers one or more tokens from the transaction signer to the recipient(s) specified.
transfer
takes a single argument of type TransferArgs
type TransferArgs = {
// pairs of recipient and token ids,
// each recipient will receive the corresponding token
transfers: {
receiverId: string;
tokenId: string;
}[];
// nftContractId is the token contract capable of doing the transfer
// if omitted, transfer method will attempt to use process.env.CONTRACT_ADDRESS
nftContractId?: string;
};
Example usage of transfer method in a hypothetical React component:
TransferComponent.ts
1
import { useState } from 'react';
2
import { useWallet } from '@mintbase-js/react';
3
import { execute, transfer, TransferArgs } from '@mintbase-js/sdk';
4
5
const TransferComponent = ({ tokenId, contractAddress }: TransferArgs): JSX.Element => {
6
const { selector, activeAccountId } = useWallet();
7
8
const handleTransfer = async (): Promise<void> => {
9
const wallet = await selector.wallet();
10
11
const transferArgs: TransferArgs = {
12
contractAddress: contractAddress,
13
transfers: [{
14
receiverId: 'mb_carol.testnet',
15
tokenId: token.tokenId,
16
}],
17
}
18
19
await execute(
20
{ wallet },
21
transfer(transferArgs),
22
);
23
};
24
25
return (
26
<div>
27
<button onClick={handleTransfer}>
28
Transfer {tokenId} of {contractAddress} from {activeAccountId} to Carol
29
</button>
30
</div>
31
);
32
}
33
Last modified 10mo ago