NFTs

Squid can be used as a cross-chain payments layer to power NFT checkout. With Squid plugged in, users can purchase NFTs with any token on any chain, in under 20 seconds.

Here is the flow:

  1. User selects the NFT they would like to purchase

  2. Build the calldata required to purchase the NFT and send to the user's wallet, using Squid's Contract calls feature.

  3. User selects the token and chain they want to pay with

  4. Estimate the amount of fromToken needed to purchase the NFT, taking into acount slippage.

  5. Get a route from the Squid API

  6. User signs transaction object returned by the Squid API.

Working example:

This example may go out of date as the owner address and price changes, but the structure is correct. This example allows the user to purchase a Moonrock from Treasure using any token on any chain.

https://github.com/0xsquid/examples/blob/main/buyNftFromAnyChain/src/index.ts

The main logic goes into a param of our /route API endpoint or getRoute SDK function called customContractCall. This feature takes an array of calls to be made by the Squid multicall contract. Here is a diagram showing the recommended sequence of calls to purchase an NFT using tokens received from a swap.

Below is an example customContractCall array.

const customContractCalls = [
      {
        callType: SquidCallType.FULL_TOKEN_BALANCE,
        target: tokenForNftPaymentAddress,
        value: "0",
        callData: approveErc20EncodeData,
        payload: {
          tokenAddress: tokenForNftPaymentAddress,
          inputPos: 1,
        },
        estimatedGas: "50000",
      },
      {
        callType: SquidCallType.DEFAULT,
        target: nftMarketPlaceAddress,
        value: "0",
        callData: buyNftEncodeData,
        payload: {
          tokenAddress: "1",
          inputPos: 1,
        },
        estimatedGas: "80000",
      },
      {
        callType: SquidCallType.DEFAULT,
        target: nftAddress,
        value: "0",
        callData: transferNftEncodeData,
        payload: {
          tokenAddress: "0x",
          inputPos: 1,
        },
        estimatedGas: "50000",
      },
      {
        callType: SquidCallType.FULL_TOKEN_BALANCE, // transfer any remaining MAGIC to the user's account
        target: tokenForNftPaymentAddress,
        value: "0",
        callData: transferErc20EncodeData,
        payload: {
          tokenAddress: tokenForNftPaymentAddress,
          inputPos: 1,
        },
        estimatedGas: "50000",
      },
    ],

Last updated