Listing an NFT for sale

You'll need to have an NFT that you want to list for sale in your wallet to start using these functions.

Create a listing

Use the useCreateSellOrder hook to list an NFT for sale. This hook will return a createSellOrder function that you can call to create a listing. The createSellOrder function takes an object with the following properties:

  • token: The token (ERC721 or ERC1155) you want to list for sale
  • price: The price you want to list the NFT for
  • fee: (Optional) The fee you want to charge for the listing
  • endTime: (Optional) The time at which the listing will expire

If you are creating a button to allow your holders to list their NFTs for sale, we recommend passing in the NFT data as props to the button component as such:

import { useCreateSellOrder } from '@cranetech/sdk'

export const CreateSellOrderButton = ({ nft, price }) => {
	// Get the createSellOrder function from the hook
  const createSellOrder = useCreateSellOrder()

	  // Create the fee object (or pass this in as a prop)
  const fee = {
    recipient: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', // Fee recipient wallet address (i.e your wallet)
    basisPoints: 500, // 5% of price
  }

	// Create a function that gets called when the button is clicked.
  const handleClick = () => {
    const response = createSellOrder({
      nft.tokenAddress,
      [nft.tokenId], // Must be in array format
      price,
      fee,
    });

    console.log(response); // if you want to debug the response
  };

  return (
    <button
      onClick={handleClick}
    >
      List NFT for sale
    </button>
  )
}

Return Value

Return Value

{
	order:OrderWithCounter, // The constructed order object that is ingested by Seaport
	isSuccess: boolean,
	isPending: boolean,
	isError:boolean,
	error: Error,
}

Expected behavior

After you call the createSellOrder function, you should see a transaction in your wallet. If it's your first time listing an NFT from a particular contract address, you will need to approve the contract to transfer your NFTs. This grants the marketplace permission to transfer the NFT to the buyer.

Once the transaction is confirmed, you can either get the constructed order from the function response or you can see the listing appear in your NFT dashboard and fetch it using useFetchOrder.

Set approvalSet approval