NFTs
Last updated
Last updated
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:
User selects the NFT they would like to purchase
Build the calldata required to purchase the NFT and send to the user's wallet, using Squid's Contract calls feature.
User selects the token and chain they want to pay with
Estimate the amount of fromToken
needed to purchase the NFT, taking into acount slippage.
Get a route from the Squid API
User signs transaction object returned by the Squid API.
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.