Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 1.8 KB

File metadata and controls

62 lines (47 loc) · 1.8 KB

Transfer Fungible Tokens

Transfers an amount of fungible tokens to a given account. Make sure that your recipient is registered with the FT contract, and that you get the decimals of the transfer right.

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

ftTransfer(args: FtTransferArgs): NearContractCall

ftTransfer takes a single argument of type FtTransferArgs

type FtTransferArgs = {
  // The FT contract whose tokens should be transferred.
  ftContractAddress: string;
  // The recipient of the FT transfer.
  receiverId: string;
  // The amount of FT to transfer in atomic units. Make sure to check the `decimals` field of this FT smart contracts metadata to avoid errors.
  amount: string;
  // An optional memo that you wish to send along with the transfer.
  memo?: string;
};

Example usage of FT transfer method in a hypothetical React component: {% code title="FtTransferComponent.ts" overflow="wrap" lineNumbers="true" %}

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

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

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

    const ftTransferArgs: FtTransferArgs = {
        ftContractAddress: "usdc.fakes.testnet",
        receiverId: "mb_carol.testnet",
        amount: "10000000"
      }

    await execute(
      { wallet },
      ftTransfer(ftTransferArgs),
    );
  };

  return (
    <div>
      <button onClick={handleFtTransfer}>
        Transfer 10 USDC to Carol
      </button>
    </div>
  );
}

{% endcode %}