Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.71 KB

File metadata and controls

65 lines (50 loc) · 1.71 KB

Transfer Tokens

Transfers one or more tokens from the transaction signer to the recipient(s) specified.

As with all new SDK api methods, this call should be wrapped in execute and passed a signing method

transfer(args: TransferArgs): NearContractCall

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: {% code title="TransferComponent.ts" overflow="wrap" lineNumbers="true" %}

import { useState } from 'react';
import { useWallet } from '@mintbase-js/react';
import { execute, transfer, TransferArgs } from '@mintbase-js/sdk';

const TransferComponent = ({ tokenId, contractAddress }: TransferArgs): JSX.Element => {
  const { selector, activeAccountId } = useWallet();

  const handleTransfer = async (): Promise<void> => {
    const wallet = await selector.wallet();

    const transferArgs: TransferArgs = {
        contractAddress: contractAddress,
        transfers: [{
          receiverId: 'mb_carol.testnet',
          tokenId: token.tokenId,
        }],
      }

    await execute(
      { wallet },
      transfer(transferArgs),
    );
  };

  return (
    <div>
      <button onClick={handleTransfer}>
        Transfer {tokenId} of {contractAddress} from {activeAccountId} to Carol
      </button>
    </div>
  );
}

{% endcode %}