Build a Trading Aggregator

Create your trading aggregator with 3rd-party order books.

1. Introduction

In this guide, we will guide you through the seamless process of establishing an NFT marketplace by utilizing GoTrading's aggregated order books, which integrate data from leading NFT marketplaces including OpenSea, Blur, LooksRare, and X2Y2. With the aid of the GoTrading SDK, not only will you be able to streamline the creation of your marketplace but also institute a revenue model that allows for the collection of a marketplace fee with every NFT transaction, thus adding a lucrative layer to your revenue generation strategy.

2. Pre-requisites

  • Kindly take some time to grasp the core concepts of business, it's vital to the integration.
  • Your API Key is prepared, make sure you have access to the endpoints. Get your API key here.

3. Create NFT Marketplace with aggregated order books

  1. Login to the developer platform and access the marketplace dashboard
  2. Choose the order book and click 'create'.
  3. Confirm the information and then the order book will be created successfully

Now you have established your NFT marketplace with aggregated order book, namely a trading aggregator! You can access and fulfill orders from all the major NFT marketplaces(Supported Marketplaces).

4. Trading NFTs with Your NFT Marketplace

Below, we provide a comprehensive guide to executing various trading operations on your NFT marketplace. Keep in mind, these operations might involve several interactions between the user's wallet and your marketplace, each facilitated by specific AggregateActions returned from the Trading API.

5. Bulk Listings with your NFT Marketplace

In this section, we explore the methodologies to facilitate bulk listings on your NFT marketplace. You'll learn how to streamline the listing process using both HTTP API and GoTrading SDK (Typescript), enabling you to manage multiple listings efficiently and effectively.

- With HTTP API

The following curl command provides an example where you merely need to replace YOUR_API_KEY with your actual API key to initiate a test request for listing an NFT on OpenSea using Create Listings API. The maker and token parameters have been populated with values from our test wallet to facilitate an immediate start. Keep in mind, in real-world scenarios, you would replace these with your DAPP request values. Let's get started:

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/create-listings?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
        "maker": "0x9398BA28015F0ce82b00CCB0da0C686a86DBad36",
        "params": [
            {
                "token": "0x3d053C1B9eF47f14E9d97e076b96c3A7C5054B1d:7079",
                "wei_price": "10000000000000",
                "order_kind": "seaport-v1.5",
                "orderbook": "opensea",
                "listing_time": "1692605611",
                "expiration_time": "1692615611",
                "quantity": 1
            }
        ]
    }'

The corresponding response is:

{
    "code": "SUCCESS",
    "msg": "success",
    "data": {
        "actions": [
            {
                "name": "nft-approval",
                "description": "Currency Approval",
                "kind": "transaction",
                "data": {
                    "order_indexes": [
                        0
                    ],
                    "tx_data": {
                        "from": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                        "to": "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                        "data": "0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001"
                    }
                }
            },
            {
                "name": "order-signature",
                "description": "Free off-chain signature to create the order",
                "kind": "signature",
                "data": {
                    "sign": {
                        "signatureKind": "eip712",
                        "domain": {
                            "name": "Seaport",
                            "version": "1.5",
                            "chainId": 1,
                            "verifyingContract": "0x00000000000000adc04c56bf30ac9d3c0aaf14dc"
                        },
                        "types": {
                            "OrderComponents": [
                                {
                                    "name": "offerer",
                                    "type": "address"
                                },
                                {
                                    "name": "zone",
                                    "type": "address"
                                },
                                {
                                    "name": "offer",
                                    "type": "OfferItem[]"
                                },
                                {
                                    "name": "consideration",
                                    "type": "ConsiderationItem[]"
                                },
                                {
                                    "name": "orderType",
                                    "type": "uint8"
                                },
                                {
                                    "name": "startTime",
                                    "type": "uint256"
                                },
                                {
                                    "name": "endTime",
                                    "type": "uint256"
                                },
                                {
                                    "name": "zoneHash",
                                    "type": "bytes32"
                                },
                                {
                                    "name": "salt",
                                    "type": "uint256"
                                },
                                {
                                    "name": "conduitKey",
                                    "type": "bytes32"
                                },
                                {
                                    "name": "counter",
                                    "type": "uint256"
                                }
                            ],
                            "OfferItem": [
                                {
                                    "name": "itemType",
                                    "type": "uint8"
                                },
                                {
                                    "name": "token",
                                    "type": "address"
                                },
                                {
                                    "name": "identifierOrCriteria",
                                    "type": "uint256"
                                },
                                {
                                    "name": "startAmount",
                                    "type": "uint256"
                                },
                                {
                                    "name": "endAmount",
                                    "type": "uint256"
                                }
                            ],
                            "ConsiderationItem": [
                                {
                                    "name": "itemType",
                                    "type": "uint8"
                                },
                                {
                                    "name": "token",
                                    "type": "address"
                                },
                                {
                                    "name": "identifierOrCriteria",
                                    "type": "uint256"
                                },
                                {
                                    "name": "startAmount",
                                    "type": "uint256"
                                },
                                {
                                    "name": "endAmount",
                                    "type": "uint256"
                                },
                                {
                                    "name": "recipient",
                                    "type": "address"
                                }
                            ]
                        },
                        "value": {
                            "kind": "single-token",
                            "offerer": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                            "zone": "0x0000000000000000000000000000000000000000",
                            "offer": [
                                {
                                    "itemType": 2,
                                    "token": "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                                    "identifierOrCriteria": "7079",
                                    "startAmount": "1",
                                    "endAmount": "1"
                                }
                            ],
                            "consideration": [
                                {
                                    "itemType": 0,
                                    "token": "0x0000000000000000000000000000000000000000",
                                    "identifierOrCriteria": "0",
                                    "startAmount": "9000000000000",
                                    "endAmount": "9000000000000",
                                    "recipient": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36"
                                },
                                {
                                    "itemType": 0,
                                    "token": "0x0000000000000000000000000000000000000000",
                                    "identifierOrCriteria": "0",
                                    "startAmount": "750000000000",
                                    "endAmount": "750000000000",
                                    "recipient": "0x03d8c18655473bf155768c8d9fd1f10a022b345f"
                                },
                                {
                                    "itemType": 0,
                                    "token": "0x0000000000000000000000000000000000000000",
                                    "identifierOrCriteria": "0",
                                    "startAmount": "250000000000",
                                    "endAmount": "250000000000",
                                    "recipient": "0x0000a26b00c1f0df003000390027140000faa719"
                                }
                            ],
                            "orderType": 0,
                            "startTime": 1692605611,
                            "endTime": 1692615611,
                            "zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                            "salt": "0x360c6ebe00000000000000000000000017e3ac68155221ed6e3633fc831927b8",
                            "conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
                            "counter": "0",
                            "signature": "0x0000000000000000000000000000000000000000000000000000000000000000"
                        },
                        "primaryType": "OrderComponents"
                    },
                    "body": {
                        "order": {
                            "kind": "seaport-v1.5",
                            "data": {
                                "kind": "single-token",
                                "offerer": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                                "zone": "0x0000000000000000000000000000000000000000",
                                "offer": [
                                    {
                                        "itemType": 2,
                                        "token": "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                                        "identifierOrCriteria": "7079",
                                        "startAmount": "1",
                                        "endAmount": "1"
                                    }
                                ],
                                "consideration": [
                                    {
                                        "itemType": 0,
                                        "token": "0x0000000000000000000000000000000000000000",
                                        "identifierOrCriteria": "0",
                                        "startAmount": "9000000000000",
                                        "endAmount": "9000000000000",
                                        "recipient": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36"
                                    },
                                    {
                                        "itemType": 0,
                                        "token": "0x0000000000000000000000000000000000000000",
                                        "identifierOrCriteria": "0",
                                        "startAmount": "750000000000",
                                        "endAmount": "750000000000",
                                        "recipient": "0x03d8c18655473bf155768c8d9fd1f10a022b345f"
                                    },
                                    {
                                        "itemType": 0,
                                        "token": "0x0000000000000000000000000000000000000000",
                                        "identifierOrCriteria": "0",
                                        "startAmount": "250000000000",
                                        "endAmount": "250000000000",
                                        "recipient": "0x0000a26b00c1f0df003000390027140000faa719"
                                    }
                                ],
                                "orderType": 0,
                                "startTime": 1692605611,
                                "endTime": 1692615611,
                                "zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                                "salt": "0x360c6ebe00000000000000000000000017e3ac68155221ed6e3633fc831927b8",
                                "conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
                                "counter": "0",
                                "signature": "0x0000000000000000000000000000000000000000000000000000000000000000"
                            }
                        },
                        "orderbook": "opensea"
                    },
                    "order_indexes": [
                        0
                    ]
                }
            },
            {
                "name": "post-order-to-marketplace",
                "description": "Post order to marketplace",
                "kind": "pass-through",
                "data": {
                    "endpoint": "/trade/v1/nft/post-order",
                    "method": "POST",
                    "payload": {
                        "order": {
                            "kind": "seaport-v1.5",
                            "data": {
                                "kind": "single-token",
                                "offerer": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                                "zone": "0x0000000000000000000000000000000000000000",
                                "offer": [
                                    {
                                        "token": "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                                        "item_type": 2,
                                        "identifier_or_criteria": "7079",
                                        "start_amount": "1",
                                        "end_amount": "1"
                                    }
                                ],
                                "consideration": [
                                    {
                                        "token": "0x0000000000000000000000000000000000000000",
                                        "recipient": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                                        "item_type": 0,
                                        "identifier_or_criteria": "0",
                                        "start_amount": "9000000000000",
                                        "end_amount": "9000000000000"
                                    },
                                    {
                                        "token": "0x0000000000000000000000000000000000000000",
                                        "recipient": "0x03d8c18655473bf155768c8d9fd1f10a022b345f",
                                        "item_type": 0,
                                        "identifier_or_criteria": "0",
                                        "start_amount": "750000000000",
                                        "end_amount": "750000000000"
                                    },
                                    {
                                        "token": "0x0000000000000000000000000000000000000000",
                                        "recipient": "0x0000a26b00c1f0df003000390027140000faa719",
                                        "item_type": 0,
                                        "identifier_or_criteria": "0",
                                        "start_amount": "250000000000",
                                        "end_amount": "250000000000"
                                    }
                                ],
                                "salt": "0x360c6ebe00000000000000000000000017e3ac68155221ed6e3633fc831927b8",
                                "counter": "0",
                                "signature": "0x0000000000000000000000000000000000000000000000000000000000000000",
                                "order_type": 0,
                                "start_time": 1692605611,
                                "end_time": 1692615611,
                                "zone_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                                "conduit_key": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000"
                            }
                        },
                        "orderbook": "opensea",
                        "order_type": "listing",
                        "extra_args": {
                            "version": "v3"
                        }
                    }
                }
            }
        ]
    },
    "status_code": 200
}

The response returns an array of AggregateActions, which can be directly relayed to your client-side application to handle each individual action. These actions fall under three categories: transaction, signature, and pass-through.

  1. action.kind = "transaction": This necessitates the wallet to initiate a transaction, granting the respective NFT marketplace contract the authorization to interact with the user's NFT. This allows the marketplace contract to transfer the NFT from the seller to the buyer during the finalization of a successful transaction on-chain. Given the response above, here's a pseudo-code example demonstrating how to handle this action:

    import Web3 from 'web3';
    
    // Sample transaction action data structure
    const sampleTransactionAction = {
        name: "nft-approval",
        description: "Currency Approval",
        kind: "transaction",
        data: {
            order_indexes: [0],
            tx_data: {
                from: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                to: "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                data: "0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001"
            }
        }
    }
    
    // Destructuring the relevant data from the action object
    const { data } = sampleTransactionAction;
    const { tx_data } = data; // Corrected the typo here
    
    // Initializing a Web3 instance with the provider URL
    const web3Provider = new Web3.providers.HttpProvider('${YOUR_PROVDER_URL}');
    const web3 = new Web3(web3Provider);
    
    // Please note that the following pseudo-code won't execute successfully 
    // as it stands. In your client-side implementation, you will need to 
    // pop up the user's wallet for transaction approval.
    web3.eth.sendTransaction({
        from: tx_data.from, // Adjusted the variable name to match the corrected destructuring
        to: tx_data.to,
        data: tx_data.data,
    })
    .catch((error) => {
        console.error("An error occurred during the transaction:", error);
    });
    
  2. action.kind = "signature": This involves the wallet signing the listing to authenticate the operation. You will then need to post the signed listing to the OpenSea in the next step. Example pseudo-code:

    import { ethers } from 'ethers';
    
    const sampleSignatureAction = {
      name: "order-signature",
      description: "Free off-chain signature to create the order",
      kind: "signature",
      data: {
        sign: {
          signatureKind: "eip712",
          domain: {
            name: "Seaport",
            version: "1.5",
            chainId: 1,
            verifyingContract: "0x00000000000000adc04c56bf30ac9d3c0aaf14dc"
          },
          types: {
            OrderComponents: [
              {
                name: "offerer",
                type: "address"
              },
              {
                name: "zone",
                type: "address"
              },
              {
                name: "offer",
                type: "OfferItem[]"
              },
              {
                name: "consideration",
                type: "ConsiderationItem[]"
              },
              {
                name: "orderType",
                type: "uint8"
              },
              {
                name: "startTime",
                type: "uint256"
              },
              {
                name: "endTime",
                type: "uint256"
              },
              {
                name: "zoneHash",
                type: "bytes32"
              },
              {
                name: "salt",
                type: "uint256"
              },
              {
                name: "conduitKey",
                type: "bytes32"
              },
              {
                name: "counter",
                type: "uint256"
              }
            ],
            OfferItem: [
              {
                name: "itemType",
                type: "uint8"
              },
              {
                name: "token",
                type: "address"
              },
              {
                name: "identifierOrCriteria",
                type: "uint256"
              },
              {
                name: "startAmount",
                type: "uint256"
              },
              {
                name: "endAmount",
                type: "uint256"
              }
            ],
            ConsiderationItem: [
              {
                name: "itemType",
                type: "uint8"
              },
              {
                name: "token",
                type: "address"
              },
              {
                name: "identifierOrCriteria",
                type: "uint256"
              },
              {
                name: "startAmount",
                type: "uint256"
              },
              {
                name: "endAmount",
                type: "uint256"
              },
              {
                name: "recipient",
                type: "address"
              }
            ]
          },
          value: {
            kind: "single-token",
            offerer: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
            zone: "0x0000000000000000000000000000000000000000",
            offer: [
              {
                itemType: 2,
                token: "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                identifierOrCriteria: "7079",
                startAmount: "1",
                endAmount: "1"
              }
            ],
            consideration: [
              {
                itemType: 0,
                token: "0x0000000000000000000000000000000000000000",
                identifierOrCriteria: "0",
                startAmount: "9000000000000",
                endAmount: "9000000000000",
                recipient: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36"
              },
              {
                itemType: 0,
                token: "0x0000000000000000000000000000000000000000",
                identifierOrCriteria: "0",
                startAmount: "750000000000",
                endAmount: "750000000000",
                recipient: "0x03d8c18655473bf155768c8d9fd1f10a022b345f"
              },
              {
                itemType: 0,
                token: "0x0000000000000000000000000000000000000000",
                identifierOrCriteria: "0",
                startAmount: "250000000000",
                endAmount: "250000000000",
                recipient: "0x0000a26b00c1f0df003000390027140000faa719"
              }
            ],
            orderType: 0,
            startTime: 1692605611,
            endTime: 1692615611,
            zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
            salt: "0x360c6ebe00000000000000000000000017e3ac68155221ed6e3633fc831927b8",
            conduitKey: "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
            counter: "0",
            signature: "0x0000000000000000000000000000000000000000000000000000000000000000"
          },
          primaryType: "OrderComponents"
        },
        body: {
          order: {
            kind: "seaport-v1.5",
            data: {
              kind: "single-token",
              offerer: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
              zone: "0x0000000000000000000000000000000000000000",
              offer: [
                {
                  itemType: 2,
                  token: "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                  identifierOrCriteria: "7079",
                  startAmount: "1",
                  endAmount: "1"
                }
              ],
              consideration: [
                {
                  itemType: 0,
                  token: "0x0000000000000000000000000000000000000000",
                  identifierOrCriteria: "0",
                  startAmount: "9000000000000",
                  endAmount: "9000000000000",
                  recipient: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36"
                },
                {
                  itemType: 0,
                  token: "0x0000000000000000000000000000000000000000",
                  identifierOrCriteria: "0",
                  startAmount: "750000000000",
                  endAmount: "750000000000",
                  recipient: "0x03d8c18655473bf155768c8d9fd1f10a022b345f"
                },
                {
                  itemType: 0,
                  token: "0x0000000000000000000000000000000000000000",
                  identifierOrCriteria: "0",
                  startAmount: "250000000000",
                  endAmount: "250000000000",
                  recipient: "0x0000a26b00c1f0df003000390027140000faa719"
                }
              ],
              orderType: 0,
              startTime: 1692605611,
              endTime: 1692615611,
              zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
              salt: "0x360c6ebe00000000000000000000000017e3ac68155221ed6e3633fc831927b8",
              conduitKey: "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
              counter: "0",
              signature: "0x0000000000000000000000000000000000000000000000000000000000000000"
            }
          },
          orderbook: "opensea"
        },
        order_indexes: [
          0
        ]
      }
    }
    
    // Prepare the data to be signed as per EIP-712 standard
    const { data } = sampleSignatureAction;
    const { sign } = data;
    const { domain, types, value } = sign;
    
    // Initialize a new ethers provider
    const provider = new ethers.providers.JsonRpcProvider('${YOUR_PROVIDER_URL}');
    
    // Initialize a wallet instance with the user's private key. 
    // NOTE: In a real implementation, never expose the private key like this. Use a wallet connect approach or similar to get the signer.
    const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
    
    // Placeholder for order signature
    let signature;
    
    wallet.signTypedData(domain, types, value)
      .then(signedData => {
        signature = signedData;
        console.log('User signed data:', signature);
      })
      .catch(error => {
        console.error('Error signing data:', error);
      });
    
    
  3. action.kind = "pass-through": This action signifies that the customer needs to use the payload to request another API. This pseudo-code snippet illustrates how to manage this action:

    import axios from 'axios';
    
    const samplePassThrough = {
      name: "post-order-to-marketplace",
      description: "Post order to marketplace",
      kind: "pass-through",
      data: {
        endpoint: "/trade/v1/nft/post-order",
        method: "POST",
        payload: {
          order: {
            kind: "seaport-v1.5",
            data: {
              kind: "single-token",
              offerer: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
              zone: "0x0000000000000000000000000000000000000000",
              offer: [
                {
                  token: "0x3d053c1b9ef47f14e9d97e076b96c3a7c5054b1d",
                  item_type: 2,
                  identifier_or_criteria: "7079",
                  start_amount: "1",
                  end_amount: "1"
                }
              ],
              consideration: [
                {
                  token: "0x0000000000000000000000000000000000000000",
                  recipient: "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                  item_type: 0,
                  identifier_or_criteria: "0",
                  start_amount: "9000000000000",
                  end_amount: "9000000000000"
                },
                {
                  token: "0x0000000000000000000000000000000000000000",
                  recipient: "0x03d8c18655473bf155768c8d9fd1f10a022b345f",
                  item_type: 0,
                  identifier_or_criteria: "0",
                  start_amount: "750000000000",
                  end_amount: "750000000000"
                },
                {
                  token: "0x0000000000000000000000000000000000000000",
                  recipient: "0x0000a26b00c1f0df003000390027140000faa719",
                  item_type: 0,
                  identifier_or_criteria: "0",
                  start_amount: "250000000000",
                  end_amount: "250000000000"
                }
              ],
              salt: "0x360c6ebe00000000000000000000000017e3ac68155221ed6e3633fc831927b8",
              counter: "0",
              signature: "0x0000000000000000000000000000000000000000000000000000000000000000",
              order_type: 0,
              start_time: 1692605611,
              end_time: 1692615611,
              zone_hash: "0x0000000000000000000000000000000000000000000000000000000000000000",
              conduit_key: "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000"
            }
          },
          orderbook: "opensea",
          order_type: "listing",
          extra_args: {
            version: "v3"
          }
        }
      }
    }
    
    const executePassThrough = async (passThroughAction) => {
      try {
        const { endpoint, method, payload } = passThroughAction.data;
        // Don't forget to assign the order signature you got from the previous step
        payload.order.signature = 'xxx'; 
    
        const response = await axios({
          url: `https://data-api.nftgo.io${endpoint}?chain=ethereum`,
          method,
          data: payload,
          headers: {
            'Content-Type': 'application/json',
            'X-API-KEY': '${YOUR_API_KEY}'
          }
        });
    
        console.log('Response:', response.data);
      } catch (error) {
        console.error('Error executing pass-through action:', error);
      }
    };
    

Upon successful posting, these listings become searchable within our aggregated order books, allowing users to view and interact with them.

If you want to bulk-list multiple NFTs, using the example below.

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/create-listings?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
        "maker": "0x9398BA28015F0ce82b00CCB0da0C686a86DBad36",
        "params": [
            {
                "token": "0x3d053C1B9eF47f14E9d97e076b96c3A7C5054B1d:7079",
                "wei_price": "10000000000000",
                "order_kind": "seaport-v1.5",
                "orderbook": "opensea",
                "listing_time": "1692605611",
                "expiration_time": "1692615611",
                "quantity": 1
            },
            {
                "token": "0x3d053C1B9eF47f14E9d97e076b96c3A7C5054B1d:7079",
                "wei_price": "10000000000000",
                "order_kind": "looks-rare-v2",
                "orderbook": "looks-rare",
                "listing_time": "1692605611",
                "expiration_time": "1692615611",
                "quantity": 1
            },
                        {
                "token": "0x3d053C1B9eF47f14E9d97e076b96c3A7C5054B1d:7078",
                "wei_price": "10000000000000",
                "order_kind": "seaport-v1.5",
                "orderbook": "opensea",
                "listing_time": "1692605611",
                "expiration_time": "1692615611",
                "quantity": 1
            },
            {
                "token": "0x3d053C1B9eF47f14E9d97e076b96c3A7C5054B1d:7078",
                "wei_price": "10000000000000",
                "order_kind": "looks-rare-v2",
                "orderbook": "looks-rare",
                "listing_time": "1692605611",
                "expiration_time": "1692615611",
                "quantity": 1
            }
        ]
    }'

- With GoTrading SDK (Typescript)

This example uses the GoTrading SDK to list an NFT to OpenSea. If you are running an NFT trading strategy service interpreting GoTrading, you can initialize the SDK with your wallet private key, we've implemented necessary utility functions for you to execute the NFT trading operations in one go.

import { CreateListingsReq, init, Orderbook, OrderKind } from '@nftgo/gotrading';
import Web3 from 'web3';

const goTrading = init({
  apiKey: "YOUR_API_KEY", // Substitute with your API key
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  walletConfig: {
    address: 'YOUR_WALLET_ADDRESS',
    privateKey: 'YOUR_WALLET_PRIVATE_KEY',
  },
  openSeaApiKeyConfig: {
    apiKey: 'YOUR_OPENSEA_API_KEY', 
    requestsPerInterval: 10, 
    interval: 1000, 
  },
  looksRareApiKeyConfig: {
    apiKey: 'YOUR_LOOKSRARE_API_KEY', 
    requestsPerInterval: 10, 
    interval: 1000, 
  }, 
  x2y2ApiKeyConfig: {
    apiKey: 'YOUR_X2Y2_API_KEY', 
    requestsPerInterval: 10, 
    interval: 1000, 
  }
});

const req: CreateListingsReq = {
  maker: "YOUR_WALLET_ADDRESS", // Your address
  params: [
    {
      token: "YOUR_NFT_TOKEN",
      weiPrice: '10000000000000',
      orderKind: OrderKind.SeaportV15,
      orderbook: Orderbook.Opensea,
      listingTime: '1692605611',
      expirationTime: '1692615611',
      quantity: 1,
    },
  ],
};

const res = await goTrading.aggregator.createListings(req);

await res.executeActions({
  onTaskExecuted: task => {
    console.info(task);
  },
});

This script utilizes the GoTrading SDK to list an NFT on OpenSea with ease. Remember to replace the placeholders with your actual API keys, wallet details, and web3 provider.

6. Create Offers with your NFT Marketplace

In this section, we'll guide you through creating offers directly through your NFT Marketplace. Similar to listing NFTs, offers can be created using either HTTP API or the GoTrading SDK. We will detail both methods here.

- With HTTP API

In this subsection, we delve into the process of creating offers using the Create Offers API, a technique quite akin to the listing creation method discussed in the previous section. This approach entails constructing a POST request furnished with the necessary details to initiate offers swiftly on your marketplace. To kickstart your journey, here is a straightforward example:

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/create-offers?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
        "maker": "0x9398BA28015F0ce82b00CCB0da0C686a86DBad36",
        "params": [
            {
                "token": "0x3d053C1B9eF47f14E9d97e076b96c3A7C5054B1d:7080",
                "wei_price": "10000000000000",
                "order_kind": "seaport-v1.5",
                "orderbook": "opensea",
                "listing_time": "1692605611",
                "expiration_time": "1692615611",
                "quantity": 1
            }
        ]
    }'

Note:

  • Remember to replace YOUR_API_KEY with your actual API key.
  • The maker field should contain your wallet address.
  • The wei_price has been set to 0.01 ETH (10,000,000,000,000 wei), adjust as necessary.
    This CURL command demonstrates a simple way to create an offer with specified parameters. Feel free to tweak the values to suit your requirements.

If you find the process familiar, it's because the structure and approach closely resemble the method utilized in creating listings. For a more detailed walkthrough, feel free to refer back to the Bulk Listings with HTTP API section anytime.

- With GoTrading SDK (Typescript)

Implementing offer creations in your backend service is simplified with the GoTrading SDK. Initialize it with your wallet's private key to execute NFT trading operations smoothly. Here is an example demonstrating how to create offers using the GoTrading SDK:

import { CreateOffersReq, init, Orderbook, OrderKind } from '@nftgo/gotrading';
import Web3 from 'web3';

const goTrading = init({
  apiKey: "YOUR_API_KEY", // Substitute with your API key
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  walletConfig: {
    address: 'YOUR_WALLET_ADDRESS',
    privateKey: 'YOUR_WALLET_PRIVATE_KEY',
  },
  openSeaApiKeyConfig: {
    apiKey: 'YOUR_OPENSEA_API_KEY', 
    requestsPerInterval: 10, 
    interval: 1000, 
  },
  looksRareApiKeyConfig: {
    apiKey: 'YOUR_LOOKSRARE_API_KEY', 
    requestsPerInterval: 10, 
    interval: 1000, 
  }, 
  x2y2ApiKeyConfig: {
    apiKey: 'YOUR_X2Y2_API_KEY', 
    requestsPerInterval: 10, 
    interval: 1000, 
  }
});

const req: CreateOffersReq = {
  maker: "YOUR_WALLET_ADDRESS", // Your address
  params: [
    {
      token: "DESIRED_NFT_TOKEN",
      weiPrice: '10000000000000',
      orderKind: OrderKind.SeaportV15,
      orderbook: Orderbook.Opensea,
      listingTime: '1692605611',
      expirationTime: '1692615611',
      quantity: 1,
    },
  ],
};

const res = await goTrading.aggregator.createListings(req);

await res.executeActions({
  onTaskExecuted: task => {
    console.info(task);
  },
});

You have now acquired the skills to automate offer creations using the GoTrading SDK. Try integrating this into your system and enhance your marketplace's functionality.

7. Query Orders

You can query the listings and offers from aggregated order books including the listings and offers that you create.

Each order has a unique order ID for further execution. Pass the order IDs of listings to buy & sweep NFTs, or order IDs of offers to sell the NFT. Here's a sample HTTP response for retrieving listings of BAYC:

{
  "code": "SUCCESS",
  "msg": "success",
  "data": {
    "listing_dtos": [
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24590000000000000000",
            "decimal": 24.59,
            "usd": 40375.1757,
            "platform": 24.59
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0xe7866592a63bd5bb4b4ecfdca2a797e4a8f63ece",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65071f3fded4efe6cbbdd538",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "8308",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694965566672,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24640000000000000000",
            "decimal": 24.64,
            "usd": 40457.27244,
            "platform": 24.64
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x86b4d38e451c707e4914ffceab9479e3a8685f98",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65072576ded4efe6cb2eaf38",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "9244",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694967150648,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24690000000000000000",
            "decimal": 24.69,
            "usd": 40539.36917,
            "platform": 24.69
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0xa4fb0e1f6ad0a87a3ec2427ca3a944c42d19d1ca",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65071e65ded4efe6cbacfbf1",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "4858",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694965348334,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24690000000000000000",
            "decimal": 24.69,
            "usd": 40539.36917,
            "platform": 24.69
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0xa4fb0e1f6ad0a87a3ec2427ca3a944c42d19d1ca",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65071e65ded4efe6cbacfc02",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "9305",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694965348335,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24750000000000000000",
            "decimal": 24.75,
            "usd": 40254.29944,
            "platform": 24.75
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x29469395eaf6f95920e59f858042f0e28d98a20b",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65050abaded4efe6cb7125f7",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "3055",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694829240947,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24760000000000000000",
            "decimal": 24.76,
            "usd": 40654.30461,
            "platform": 24.76
          }
        },
        "status": "active",
        "kind": "seaport-v1.5",
        "maker": "0x86b4d38e451c707e4914ffceab9479e3a8685f98",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "650724a0ded4efe6cb1ef56e",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "9244",
        "market_id": "opensea",
        "is_private": false,
        "order_create_time": 1694966943181,
        "order_expiration_time": 1695053329000,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24859900000000000000",
            "decimal": 24.8599,
            "usd": 40433.04479,
            "platform": 24.8599
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x29469395eaf6f95920e59f858042f0e28d98a20b",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6504a63dded4efe6cb30c3cb",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "3622",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694803515932,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24949900000000000000",
            "decimal": 24.9499,
            "usd": 40579.42406,
            "platform": 24.9499
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x524802b34cb508be2062d02a6e1cf577c2e66fba",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65049cd3ded4efe6cb7d9e97",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "5888",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694801106248,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "24990000000000000000",
            "decimal": 24.99,
            "usd": 40644.64416,
            "platform": 24.99
          }
        },
        "status": "active",
        "kind": "seaport-v1.5",
        "maker": "0x72f3151630707826cac379f561b1bb42dd73ae99",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65049d88ded4efe6cb8baa65",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "3238",
        "market_id": "opensea",
        "is_private": false,
        "order_create_time": 1694801287701,
        "order_expiration_time": 1695406022000,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25000000000000000000",
            "decimal": 25,
            "usd": 40193.41742,
            "platform": 25
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x29469395eaf6f95920e59f858042f0e28d98a20b",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6502729c9988f1224318dbdd",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "2010",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694659227271,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25500000000000000000",
            "decimal": 25.5,
            "usd": 41474.12669,
            "platform": 25.5
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x1f8c3ea88b4de2fb0684531a449b4e9e275d85e0",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65056709ded4efe6cbd2b3e3",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "7951",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694852873306,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25500000000000000000",
            "decimal": 25.5,
            "usd": 40997.28577,
            "platform": 25.5
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x29469395eaf6f95920e59f858042f0e28d98a20b",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6502c2a3ded4efe6cb1e20c3",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "1780",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694679714261,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25900000000000000000",
            "decimal": 25.9,
            "usd": 42124.70123,
            "platform": 25.9
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x3e6527de2cfec82ce5240d5559a8b09d256d5d6d",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6505809eded4efe6cbdbff72",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "8199",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694859422119,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25990000000000000000",
            "decimal": 25.99,
            "usd": 42673.88436,
            "platform": 25.99
          }
        },
        "status": "active",
        "kind": "seaport-v1.5",
        "maker": "0x2e7573445b46a305f6b80f86ba56e788b2db7e68",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "650727f5ded4efe6cb5a68fa",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "6190",
        "market_id": "opensea",
        "is_private": false,
        "order_create_time": 1694967796578,
        "order_expiration_time": 1695054192000,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25990000000000000000",
            "decimal": 25.99,
            "usd": 42673.88436,
            "platform": 25.99
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x29469395eaf6f95920e59f858042f0e28d98a20b",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6507222dded4efe6cbf29441",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "9126",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694966316500,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "25999800000000000000",
            "decimal": 25.9998,
            "usd": 42689.97532,
            "platform": 25.9998
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x0097b9cfe64455eed479292671a1121f502bc954",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6506cbb6ded4efe6cb9d9c94",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "5723",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694944181103,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "26000000000000000000",
            "decimal": 26,
            "usd": 42287.34487,
            "platform": 26
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x78367007b9d54e0d4d5d8554865e96c8b579fdcb",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "6504bc37ded4efe6cbc98da4",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "4772",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694809142658,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "26000000000000000000",
            "decimal": 26,
            "usd": 42287.34487,
            "platform": 26
          }
        },
        "status": "active",
        "kind": "blur",
        "maker": "0x95425e5abb5cece0c5653dd77be02b7913e53488",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "650420c0ded4efe6cb6da00a",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "8128",
        "market_id": "blur",
        "is_private": false,
        "order_create_time": 1694769343923,
        "order_expiration_time": 0,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "26240000000000000000",
            "decimal": 26.24,
            "usd": 43084.36805,
            "platform": 26.24
          }
        },
        "status": "active",
        "kind": "seaport-v1.5",
        "maker": "0x1e04bfb945dfa23ed8bdea67947ca0d7b5fff75d",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65072045ded4efe6cbd1f2f4",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "3881",
        "market_id": "opensea",
        "is_private": false,
        "order_create_time": 1694965828359,
        "order_expiration_time": 1695005424000,
        "quantity_remaining": 1,
        "total_quantity": 1
      },
      {
        "price": {
          "currency": {
            "chain": "ETH",
            "symbol": "ETH",
            "decimals": 18,
            "contract_address": "0x0000000000000000000000000000000000000000"
          },
          "amount": {
            "raw": "26240000000000000000",
            "decimal": 26.24,
            "usd": 43084.36805,
            "platform": 26.24
          }
        },
        "status": "active",
        "kind": "seaport-v1.5",
        "maker": "0x1e04bfb945dfa23ed8bdea67947ca0d7b5fff75d",
        "taker": "0x0000000000000000000000000000000000000000",
        "order_id": "65072045ded4efe6cbd1f2fe",
        "contract_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
        "token_id": "8807",
        "market_id": "opensea",
        "is_private": false,
        "order_create_time": 1694965828636,
        "order_expiration_time": 1695005424000,
        "quantity_remaining": 1,
        "total_quantity": 1
      }
    ]
  },
  "status_code": 200
}

8. Buying NFTs with your NFT Marketplace and collecting marketplace fee

In this section, we will walk you through the steps to set up a successful revenue stream on your NFT marketplace through the facilitation of NFT purchases and the collection of marketplace fees. Implementing a fee collection mechanism can serve as a consistent revenue source, enhancing the profitability of your platform.

- With HTTP API

In this subsection, we illustrate how to set up transactions and facilitate the buying of NFTs using the Fulfill Listings API. This streamlined method allows for the easy implementation of a marketplace fee collection mechanism, which is crucial for sustaining and growing your marketplace.

To get started, you'll need to craft a POST request that includes the necessary details for processing transactions and collecting a marketplace fee. Below is a simplified example to help you kickstart this process:

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/fulfill-listings?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
        "buyer": "0x9398BA28015F0ce82b00CCB0da0C686a86DBad36",
        "order_ids": ["xxx"] // Place the order IDs you want to fulfill here
        "marketplace_fees_on_top":["0x00000000000000adc04c56bf30ac9d3c0aaf14dc:50000000000"]  // Marketplace fee in wei
    }'

In the code snippet above, you only need to make a couple of adjustments:

  1. Replace YOUR_API_KEY with the actual API key you have.
  2. Populate the order_ids array with the specific order IDs you intend to fulfill. These IDs can be obtained through a previous API response or a query to your database.

The fee_on_top parameter allows you to levy an additional marketplace fee in wei, over and above the order's execution price, enabling you to generate revenue from each transaction through your marketplace. It's essential to strategize this fee to ensure a harmonious balance between profitability for your platform and fair pricing for your users.

After making a successful API request, you will receive a response that contains detailed information necessary to execute a transaction to complete the purchase of an NFT. The response holds the blueprint for crafting a transaction that you need to submit to the blockchain to actualize the buying operation. Let's break down the critical components of the response and how to utilize them effectively:

{
    "statusCode": 200,
    "code": "SUCCESS",
    "msg": "success",
    "data": {
        "actions": [
            {
                "name": "fulfill-listing",
                "description": "fulfill listings",
                "kind": "transaction",
                "data": {
                    "txData": {
                        "from": "0x9398ba28015f0ce82b00ccb0da0c686a86dbad36",
                        "to": "0x00000000000000adc04c56bf30ac9d3c0aaf14dc",
                        "value": "0x0822be2c892000",
                        "data": "0x0000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000081854435a5c0000000000000000000000000077df66611c9d48cbdad25d40ec60045a27315459000000000000000000000000004c00500000ad104d7dbd00e3ae0a5c00560c000000000000000000000000004ebb2384cc1e86f578e37f2057b336b9027cb95a000000000000000000000000000000000000000000000000000000000000c8b8000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064fd9d3c0000000000000000000000000000000000000000000000000000000065252a3c000000000000000000000000000000000000000000000000000000000000000072db8c0b0000000000000000000000000000000000000000007bc540a7d310020000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000a69e92ec4000000000000000000000000000000a26b00c1f0df003000390027140000faa719000000000000000000000000000000000000000000000000000000000000004018e95db5ddd5a3de0d16839a905cc08c8f987431ab640055978fba8c6dab17dbe5907ccc2bd87a1b2d766df04d7e519b814c2ddcdace6b85b0028b3aa13f38d51d4da48b00000000ff738719"
                    },
                    "usedGas": 153700,
                    "gasLimit": 184440,
                    "txAssociatedOrderIds": [
                        "64fd9d459988f1224310f0d2"
                    ],
                    "safeMode": false
                }
            }
        ]
    }
}

In the response, you will notice various fields containing vital information that facilitates the buying operation on your NFT marketplace. Here's a breakdown for key fields:

  • actions: List of action objects, including some important fields below
    • name: Action name "fulfill-listing" means the transaction is for listing fulfilling;
    • data.txData: Encapsulates the core details necessary to formulate the transaction;
    • data.safeMode: Safe mode is on/off. Check out more details.

πŸ””

Note

This response doesn't confirm a completed transaction. Instead, it provides the blueprint you'll need to initiate to finalize the buying process.

Once the transaction is successfully executed on the blockchain, it signifies the settlement of the buy NFT operation, effectively finalizing the purchase and transferring the NFT's ownership. Moreover, you have the option to include multiple orderIds within the order_ids array in your initial API request, facilitating the sweeping of several orders in a single transaction.

This feature optimizes the transaction process, and potentially saves gas fees, enhancing the user experience especially for those looking to perform bulk operations.

- With GoTrading SDK (Typescript)

To execute the buying of NFTs in your marketplace, leverage the GoTrading SDK within a TypeScript environment. This straightforward code snippet demonstrates how to set up and execute a purchase:

import { FulfillListingsReq, init } from '@nftgo/gotrading';
import Web3 from 'web3';

const goTrading = init({
  apiKey: "YOUR_API_KEY", 
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  walletConfig: {
    address: 'YOUR_WALLET_ADDRESS',
    privateKey: 'YOUR_WALLET_PRIVATE_KEY',
  }
});

const req: FulfillListingsReq = {
  buyer: "YOUR_WALLET_ADDRESS",
  orderIds: ['xxx']
};

const res = await goTrading.aggregator.fulfillListings(req);

await res.executeActions({
  onTaskExecuted: task => {
    console.info(task);
  },
});

In the script above, the GoTrading SDK is initialized with necessary configurations including API keys and wallet details. Subsequently, a FulfillListingsReq object is created containing the details of the buyer and the order IDs to be fulfilled. The fulfillListings method on the aggregator instance initiates the buying process, with the onTaskExecuted callback functioning to monitor each task executed during the process.

Ensure to replace the placeholders with your actual data before running the script. This code forms a critical part of your strategy tool backend, allowing for automated and efficient NFT purchasing operations. Remember to safeguard your API keys and wallet details throughout this process.

9. Selling NFTs with your NFT Marketplace and collecting marketplace fee

In the context of your NFT marketplace, selling NFTs is defined as fulfilling existing NFT offers. This crucial operation serves as a cornerstone in sustaining a vibrant and active marketplace. In the following sections, we will explore the API endpoint and the GoTrading SDK that will assist in implementing this feature effectively.

- With HTTP API

To streamline the sales process within your marketplace, consider leveraging the Fulfill Offers API, specially designed for this operation. The following curl example demonstrates how to invoke this API:

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/fulfill-offers?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
      "seller_address": "SELLER_ADDRESS",
      "offer_fulfillment_intentions": [
        {
          "contract_address": "CONTRACT_ADDRESS",
          "order_id": "ORDER_ID",
          "quantity": 1,
          "token_id": "TOKEN_ID"
        }
      ],
      "marketplace_fees_on_top": ["MARKETPLACE_WALLET_ADDRESS:FEE_IN_WEI"] // Marketplace fee in wei
    }'

Before executing, undertake the following adjustments to customize the API request to your needs:

  1. Substitute YOUR_API_KEY with your authentic API key.
  2. Alter CONTRACT_ADDRESS, TOKEN_ID, and ORDER_ID with the specific details of the NFT you're selling and the offer's order ID you are selling into.
  3. The fee_on_top parameter empowers you to earn revenue based on the execution price of the offer, providing a revenue-generating avenue with every transaction.

Following a successful API request, you will receive a structured response containing details necessary for transaction execution. This response will be similar in structure to the one discussed in the "Buying NFTs" section, comprising vital details to process the transaction on the blockchain.

- With GoTrading SDK (Typescript)

In addition to using HTTP API, you can leverage the GoTrading SDK for a more streamlined and code-integrated approach to selling NFTs on your marketplace. Here's a basic example demonstrating how to implement this using TypeScript:

import { init, FulfillOffersReq } from '@nftgo/gotrading';
import Web3 from 'web3';

const goTrading = init({
  apiKey: "YOUR_API_KEY", // Replace with your own API Key.
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  web3Provider: provider,
  walletConfig: {
    address: "YOUR_WALLET_ADDRESS",
    privateKey: "YOUR_PRIVATE_KEY"
  }, // Replace with your wallet info.
});

const req: FulfillOffersReq = {
  sellerAddress: "YOUR_WALLET_ADDRESS",
  offerFulfillmentIntentions: [{
      contractAddress:'CONTRACT_ADDRESS',
      orderId: 'ORDER_ID',
      quantity: 1,
      tokenId: 'TOKEN_ID',
  }]
};

const res = await goTrading.aggregator.fulfillOffers(req);

await res.executeActions({
  onTaskExecuted: task => {
    console.info(task);
  },
});

In the script:

  1. Necessary modules are imported and the GoTrading SDK is initialized with your API key, web3 provider, and wallet configuration.
  2. A FulfillOffersReq object is crafted with the pertinent details for the sell order, including the seller address and an array detailing the offers to fulfill.
  3. The fulfillOffers method on the aggregator instance is used to initiate the selling process, with the onTaskExecuted callback monitoring the progress of each task during the transaction process.

Before running the script, replace placeholder values with your actual data. Remember to adhere to best practices by securing your API keys and wallet details.

10. Cancelling Listings & Offers with your NFT Marketplace

Cancelling listings and offers is a critical functionality in maintaining a user-friendly NFT marketplace. It is vital to note that the cancellation process is an on-chain operation, necessitating users to initiate a transaction that marks the respective order as cancelled on the blockchain. This functionality allows sellers to have better control over their assets, withdrawing them if they choose to change their strategies or prices. Similarly, buyers can retract offers that are no longer aligned with their interests.

In this section, we will guide you through the process of incorporating this essential feature into your marketplace, utilizing both HTTP API and GoTrading SDK (Typescript). Implementing a smooth cancellation process enhances user satisfaction and maintains a fluid and responsive marketplace environment.

- With HTTP API

To facilitate the seamless cancellation of listings and offers within your NFT marketplace, the Cancel Orders API presents a reliable solution. Implementing this feature requires crafting API requests that target specific endpoints designed to handle cancellations. Here’s a step-by-step guide to set this up:

Cancelling a Listing

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/cancel-orders?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
      "caller_address": "CALLER_ADDRESS",
      "orders": "[
          {
              "order_id": "LISTING_ID",
              "order_type": "listing"
          }
      ]"
    }'

In the above script:

  1. Replace YOUR_API_KEY with your actual API key.
  2. Substitute CALLER_ADDRESS with the address associated with the seller initiating the cancellation.
  3. Replace LISTING_ID with the unique identifier of the listing that is to be cancelled.

Cancelling an Offer

curl --location --request POST 'https://data-api.nftgo.io/trade/v1/nft/cancel-orders?chain=ethereum' \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: YOUR_API_KEY' \
    --data '{
      "caller_address": "CALLER_ADDRESS",
      "orders": "[
          {
              "order_id": "OFFER_ID",
              "order_type": "offer"
          }
      ]"
    }'

In this request:

  1. Replace YOUR_API_KEY with your actual API key.
  2. Substitute CALLER_ADDRESS with the address associated with the buyer initiating the cancellation.
  3. Replace OFFER_ID with the unique identifier of the offer that is to be cancelled.

- With GoTrading SDK (Typescript)

To enable cancellation functionalities within a TypeScript environment, the GoTrading SDK offers an intuitive approach. Below are code snippets demonstrating how to cancel listings and offers, respectively:

Cancelling a Listing

import { CancelOrdersReq, init, OrderType } from '@nftgo/gotrading';
import Web3 from 'web3';

const goTrading = init({
  apiKey: "YOUR_API_KEY", 
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  walletConfig: {
    address: 'YOUR_WALLET_ADDRESS',
    privateKey: 'YOUR_WALLET_PRIVATE_KEY',
  }
});

const req: CancelOrdersReq = {
  callerAddress: "YOUR_WALLET_ADDRESS",
  orders: [{
      orderId: 'LISTING_ID',
      orderType: OrderType.Listing,
  }]
};

const res = await goTrading.aggregator.cancelOrders(req);

await res.executeActions({
  onTaskExecuted: task => {
    console.info(task);
  },
});

Cancelling an Offer

import { CancelOrdersReq, init, OrderType } from '@nftgo/gotrading';
import Web3 from 'web3';

const goTrading = init({
  apiKey: "YOUR_API_KEY", 
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  walletConfig: {
    address: 'YOUR_WALLET_ADDRESS',
    privateKey: 'YOUR_WALLET_PRIVATE_KEY',
  }
});

const req: CancelOrdersReq = {
  callerAddress: "YOUR_WALLET_ADDRESS",
  orders: [{
      orderId: 'OFFER_ID',
      orderType: OrderType.Offer,
  }]
};

const res = await goTrading.aggregator.cancelOrders(req);

await res.executeActions({
  onTaskExecuted: task => {
    console.info(task);
  },
});

In both scripts:

  1. Substitute the placeholders with actual data, including YOUR_API_KEY, YOUR_WEB3_PROVIDER, YOUR_WALLET_ADDRESS, and YOUR_WALLET_PRIVATE_KEY.
  2. For cancelling orders use CancelOrdersReq.
  3. The onTaskExecuted callback functions as a monitoring tool for each task executed during the process, providing real-time feedback.
    This way, you can streamline the cancellation process within your NFT marketplace, enhancing user satisfaction by offering them greater control and flexibility over their listings and offers.

Cancelling X2Y2 Orders

To cancel X2Y2 orders, you have to pass the X2Y2 sign and sign_message parameters. Our GoTrading SDK has encapsulated the corresponding utils function to sign the X2Y2 required message. Here's the code sample demonstrating how to get X2Y2 sign and sign_message using GoTrading SDK:

import {init} from "@nftgo/gotrading";

const goTrading = init({
  apiKey: process.env.API_KEY!, // Substitute with your API key
  web3Provider: new Web3.providers.HttpProvider("YOUR_WEB3_PROVIDER"),
  walletConfig: {
    address: process.env.MOCK_MAKER_ADDRESS!,
    privateKey: process.env.PRIVATE_KEY!,
  }
});

const result = await goTrading.utils.x2y2Authenticator.authorize({
  address: process.env.MOCK_MAKER_ADDRESS!,
})

const sign = result.signature;
const signMessage = result.message;

Then pass these two parameters into theextraArgs at https://docs.nftgo.io/reference/post_trade-v1-nft-cancel-orders API to cancel X2Y2 orders.

You can find the x2y2Authenticator source code at hhttps://github.com/NFTGo/GoTrading/blob/master/src/modules/utils/x2y2-auth.ts#L5.

πŸ‘

Congratulations!

You've learnt all the necessary knowledge about creating a marketplace! Now you can enjoy trading NFTs on your own marketplace!