๐Ÿ–ผ
Transfer NFTs
Transfer NFTs on any blockchain - ETH (Ethereum), BNB (Binance Smart Chain), MATIC (Polygon)

Transfer ERC721 Tokens (Non-Fungible)

To transfer ERC721 tokens, follow the steps:
  1. 1.
    Construct anoptionsobject and set
    1. 1.
      type:"erc721"
    2. 2.
      receiver: "0x000..." //wallet address
    3. 3.
      contractAddress: "0x..." //contract of the ERC721 token
    4. 4.
      tokenId: 1
  2. 2.
    Call the Moralis transfer function as shown below
As it's only possible to transfer one ERC721 at a time, no amountisneeded.
JS
React
1
// sending a token with token id = 1
2
const options = {
3
type: "erc721",
4
receiver: "0x..",
5
contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
6
tokenId: 1,
7
};
8
let transaction = await Moralis.transfer(options);
Copied!
1
import React from "react";
2
import { useWeb3Transfer } from "react-moralis";
3
โ€‹
4
const TransferNFT = () => {
5
const { fetch, error, isFetching } = useWeb3Transfer({
6
type: "erc721",
7
receiver: "0x..",
8
contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
9
tokenId: 1,
10
});
11
โ€‹
12
return (
13
// Use your custom error component to show errors
14
<div>
15
{error && <ErrorMessage error={error} />}
16
<button onClick={() => fetch()} disabled={isFetching}>
17
Transfer
18
</button>
19
</div>
20
);
21
};
Copied!

Transferring ERC1155 Tokens (Semi-Fungible)

To transfer ERC1155 tokens, follow the steps:
  1. 1.
    Construct anoptionsobject and set
    1. 1.
      type:"erc721"
    2. 2.
      receiver: "0x000..." //wallet address
    3. 3.
      contractAddress: "0x..." //contract of the ERC721 token
    4. 4.
      tokenId: 1
    5. 5.
      amount: 15 //number of tokens to transfer
  2. 2.
    Call the Moralis transfer function as shown below
JS
React
1
// sending 15 tokens with token id = 1
2
const options = {
3
type: "erc1155",
4
receiver: "0x..",
5
contractAddress: "0x..",
6
tokenId: 1,
7
amount: 15,
8
};
9
let transaction = await Moralis.transfer(options);
Copied!
1
import React from "react";
2
import { useWeb3Transfer } from "react-moralis";
3
โ€‹
4
const TransferNFT = () => {
5
const { fetch, error, isFetching } = useWeb3Transfer({
6
type: "erc1155",
7
receiver: "0x..",
8
contractAddress: "0x..",
9
tokenId: 1,
10
amount: 15,
11
});
12
โ€‹
13
return (
14
// Use your custom error component to show errors
15
<div>
16
{error && <ErrorMessage error={error} />}
17
<button onClick={() => fetch()} disabled={isFetching}>
18
Transfer
19
</button>
20
</div>
21
);
22
};
Copied!

Resolving the results

Moralis.transfer() returns a transaction response after it is executed. The below page shows how to consume the data returned.