Moralis 轉(zhuǎn)移NFTs

2022-05-11 17:19 更新

轉(zhuǎn)移 ERC721 代幣(不可替代)

要轉(zhuǎn)移 ERC721 代幣,請執(zhí)行以下步驟:

  1. 構造一個options對象并設置:
    1. type:“erc721”
    2. receiver: "0x000..." //錢包地址
    3. contractAddress: "0x..." //ERC721 代幣的合約
    4. tokenId:1
  2. 調(diào)用 Moralis 傳遞函數(shù)如下圖,你可以使用?JS?或者?React?
// sending a token with token id = 1
const options = {
  type: "erc721",
  receiver: "0x..",
  contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
  tokenId: 1,
};
let transaction = await Moralis.transfer(options);
import React from "react";
import { useWeb3Transfer } from "react-moralis";

const TransferNFT = () => {
  const { fetch, error, isFetching } = useWeb3Transfer({
    type: "erc721",
    receiver: "0x..",
    contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    tokenId: 1,
  });

  return (
    // Use your custom error component to show errors
    <div>
      {error && <ErrorMessage error={error} />}
      <button onClick={() => fetch()} disabled={isFetching}>
        Transfer
      </button>
    </div>
  );
};

轉(zhuǎn)移 ERC1155 代幣(半同質(zhì)化)

要轉(zhuǎn)移 ERC1155 代幣,請按以下步驟操作:

  1. 構造一個options對象并設置:
    1. type:“erc721”
    2. receiver: "0x000..." //錢包地址
    3. contractAddress: "0x..." //ERC721 代幣的合約
    4. tokenId:1
    5. amount: 15 //要轉(zhuǎn)賬的代幣數(shù)量
  2. 調(diào)用 Moralis 傳遞函數(shù)如下圖,你可以使用?JS?或者?React?
// sending 15 tokens with token id = 1
const options = {
  type: "erc1155",
  receiver: "0x..",
  contractAddress: "0x..",
  tokenId: 1,
  amount: 15,
};
let transaction = await Moralis.transfer(options);
import React from "react";
import { useWeb3Transfer } from "react-moralis";

const TransferNFT = () => {
  const { fetch, error, isFetching } = useWeb3Transfer({
    type: "erc1155",
    receiver: "0x..",
    contractAddress: "0x..",
    tokenId: 1,
    amount: 15,
  });

  return (
    // Use your custom error component to show errors
    <div>
      {error && <ErrorMessage error={error} />}
      <button onClick={() => fetch()} disabled={isFetching}>
        Transfer
      </button>
    </div>
  );
};

解決結果

?Moralis.transfer()? 執(zhí)行后返回交易響應。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號