NFT Transfer

NFT Transfer

Magic's SDK offers out-of-the-box UI to transfer NFTs from your user’s wallet to any other wallet on the same network. It supports both single and batch transfers. For ERC-721 contracts, the the transferFrom function is invoked, while for ERC-1155 it will be the safeTransferFrom function.

Note: NFT transfers is only available on Polygon at this time. For Ethereum or other EVM based chains, contact us or your customer sucess rep.

#Use Cases

  • End-user NFT management: If you use Dedicated Wallet or Universal Wallet with our Widget UI, end-users can easily manage their NFTs through the "Collectibles" tab and transfer any NFTs. They will need to pay the gas fees for the transaction, and we will provide them with an estimate before sending.
  • Direct NFT transfer flow: Developers can initiate an NFT transfer flow directly from the SDK with pre-filled inputs to minimize the steps for the user

#Usage

note

To use this feature, you must be on version 19.2.x or above for the magic-sdk.

With the Widget UI for end-user NFT management:

Javascript
01import { Magic } from 'magic-sdk';
02
03let magic;
04
05// Get your API key from dashboard.magic.link
06magic = new Magic('YOUR_LIVE_PUBLISHABLE_API_KEY');
07
08// Log in the user
09const isLoggedIn = await magic.user.isLoggedIn();
10if (!isLoggedIn) {
11    await magic.wallet.connectWithUI();
12}
13
14await magic.wallet.showUI(); // display a fully navigable wallet with access to NFTs and NFT transfers
15
16// or
17
18await magic.wallet.showNFTs(); // directly displays a list of the user's NFTs

Using the SDK to initiate a transfer:

Javascript
01import { Magic } from 'magic-sdk';
02
03let magic;
04
05// Get your API key from dashboard.magic.link
06magic = new Magic('YOUR_LIVE_PUBLISHABLE_API_KEY');
07
08// Log in the user
09const isLoggedIn = await magic.user.isLoggedIn();
10if (!isLoggedIn) {
11    await magic.wallet.connectWithUI();
12};
13
14// Send a known NFT in the user's wallet
15const response = await magic.nft.transfer(
16    {
17        contractAddress: "0x1234567890",
18        tokenId: '1',
19        quantity: 2, // optional
20        recipient: "0x0987654321" // optional
21    }
22);
23
24const transferComplete = response.status === 'complete';

Note: The user will be prompted with a confirmation screen prior to the transaction going through.

NFT Transfer