Transfer NFTs from your wallet to another address
wallets:transactions.create
transferFrom
import { encodeFunctionData } from 'viem'; const fromAddress = '0x...'; // Your wallet address const toAddress = '0x...'; // Recipient address const tokenId = '1'; // The NFT token ID // Encode the transfer function data const data = encodeFunctionData({ abi: [{ name: 'transferFrom', type: 'function', inputs: [ { name: 'from', type: 'address' }, { name: 'to', type: 'address' }, { name: 'tokenId', type: 'uint256' } ], outputs: [], stateMutability: 'nonpayable' }], args: [fromAddress, toAddress, tokenId] }); console.log(data); // > 0x23b872dd0000000000000000000000000000000000000000000000000000000000000001
const walletLocator = '0x...'; const apiKey = 'sk_staging...'; const signerAddress = '0x...'; async function sendTransaction() { const response = await fetch( `https://api.crossmint.com/2022-06-09/wallets/${walletLocator}/transactions`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-API-KEY': apiKey, }, body: JSON.stringify({ params: { calls: [{ to: nftContractAddress, value: '0', data: data }], chain: 'polygon-amoy', }, }), } ); return await response.json(); }
Was this page helpful?