Create Swap / Offer

Endpoint to create a new swap or offer on a listed NFT

Create swap / offer

POST https://api.withmystic.xyz/marketplace-api/create-swap

This endpoint will receive what assets the creator is offering (offer) and what assets they're requesting in return (consideration). It will return both the approvals and the message to be signed by the user's wallet, necessary to create the swap/offer.

Headers

Name
Type
Description

Bearer*

String

Your API key

Request Body

Name
Type
Description

endTime

Unix Timestamp

Swap duration. Max duration assumed if unspecified

chainId*

Number

Blockchain identifier

offerer*

String

Wallet address of the swap or offer's creator

offer.itemType*

String

Asset type (NATIVE / ERC20 / ERC721 / ERC1155)

offer.token*

String

Offered asset's contract address

offer.identifier*

String

Offered asset's token ID

offer.amount*

String

Token amount (1 for NFTs). All ERC 20 amounts should be written as (number*10*18)

consideration.itemType*

String

Asset type ( NATIVE / ERC20 / ERC721 / ERC1155)

consideration.token*

String

Requested asset's contract address

consideration.identifier*

String

Requested asset's token ID

consideration.offer*

String

Amount of the asset requested

takerAddress

String

Address of the intended trade recipient, in case this is a private trade

fees.recipient

String

Address that receives creator fee

fees.basispoints

Number

creator fee in basis points (100 is 1%)

{
   "signTypedMessage":{
      "domainData":{
         "name":"Seaport",
         "version":"1.5",
         "chainId":5,
         "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":{
         "offerer":"0xA79d4cCC70Cc3DD01f7D3a70ED5C7ca73de812C4",
         "zone":"0xF712B2B35a06016851ADd2f9c43785Ec29e243dE",
         "zoneHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
         "startTime":"1692903204",
         "endTime":"115792089237316195423570985008687907853269984665640564039457584007913129639935",
         "orderType":2,
         "offer":[
            {
               "itemType":2,
               "token":"0x037aca480459ae361a87b023f189532d80cb6769",
               "identifierOrCriteria":"46",
               "startAmount":"1",
               "endAmount":"1"
            },
            {
               "itemType":2,
               "token":"0x229dd7144fec1008dddf5fcf779ec63c3d576aa7",
               "identifierOrCriteria":"36",
               "startAmount":"1",
               "endAmount":"1"
            }
         ],
         "consideration":[
            {
               "itemType":0,
               "token":"0x0000000000000000000000000000000000000000",
               "identifierOrCriteria":"0",
               "startAmount":"2970000000000000",
               "endAmount":"2970000000000000",
               "recipient":"0xA79d4cCC70Cc3DD01f7D3a70ED5C7ca73de812C4"
            },
            {
               "itemType":0,
               "token":"0x0000000000000000000000000000000000000000",
               "identifierOrCriteria":"0",
               "startAmount":"30000000000000",
               "endAmount":"30000000000000",
               "recipient":"0xF712B2B35a06016851ADd2f9c43785Ec29e243dE"
            }
         ],
         "totalOriginalConsiderationItems":2,
         "salt":"0x00000000000000000000000000000000000000000000000000000120de4ae00b",
         "conduitKey":"0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
         "counter":"0"
      }
   },
   "approvalsNeeded":[
      {
         "data":"0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001",
         "to":"0x037acA480459Ae361a87b023f189532d80cB6769"
      },
      {
         "data":"0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001",
         "to":"0x229dd7144FEC1008dDdF5fcF779Ec63c3D576aa7"
      }
   ],
   "swapId":"64e7a728c70af13605f2fb11"
}

The swap / offer needs to be validated before it is effectively created and can be accepted by someone. From here, proceed to check out Validate Swap / Offer to learn how to implement validation.

Swaps can be public or private. If you want to make it private and let only one address accept the swap, pass their address in the optional "takerAddress" parameter.

Example

Let's simulate creating a swap with this endpoint. Let's say I want to offer Mystical Wizard NFT #633 for Mystical Wizard NFT #34 + 0.5 ETH in a public trade that has a 5% royalty. This is what would be created:

{
  "endTime": "1691814254",
  "chainId": 1,
  "offerer": "0x123456789abcdef145216789abcdef123456787f",
  "fees": [
      {
      "recipient": "0x123456789abcdef145216789fcfcf123456745d",
      "basisPoints": 500,
    }
  ],
  "offer": [
    {
      "itemtype": "ERC721",
      "token": "0x74cb5611e89078b2e5cb638a873cf7bddc588659",
      "identifier": "633",
      "amount": "1"
    }
  ],
  "consideration": [
        {
      "itemtype": "ERC721",
      "token": "0x74cb5611e89078b2e5cb638a873cf7bddc588659",
      "identifier": "34",
      "amount": "1"
    },
    {
      "itemtype": "NATIVE",
      "token": "0x123456789abcdef123456789abcdef123456789a",
      "identifier": "ETH",
      "amount": "500000000000000000"
    }
  ]
}

And here we can find a response we could get from making this call (mock values):

{
   "signTypedMessage":{
      "domainData":{
         "name":"Seaport",
         "version":"1.5",
         "chainId":5,
         "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":{
         "offerer":"0xA79d4cCC70Cc3DD01f7D3a70ED5C7ca73de812C4",
         "zone":"0xF712B2B35a06016851ADd2f9c43785Ec29e243dE",
         "zoneHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
         "startTime":"1692903204",
         "endTime":"115792089237316195423570985008687907853269984665640564039457584007913129639935",
         "orderType":2,
         "offer":[
            {
               "itemType":2,
               "token":"0x037aca480459ae361a87b023f189532d80cb6769",
               "identifierOrCriteria":"46",
               "startAmount":"1",
               "endAmount":"1"
            },
            {
               "itemType":2,
               "token":"0x229dd7144fec1008dddf5fcf779ec63c3d576aa7",
               "identifierOrCriteria":"36",
               "startAmount":"1",
               "endAmount":"1"
            }
         ],
         "consideration":[
            {
               "itemType":0,
               "token":"0x0000000000000000000000000000000000000000",
               "identifierOrCriteria":"0",
               "startAmount":"2970000000000000",
               "endAmount":"2970000000000000",
               "recipient":"0xA79d4cCC70Cc3DD01f7D3a70ED5C7ca73de812C4"
            },
            {
               "itemType":0,
               "token":"0x0000000000000000000000000000000000000000",
               "identifierOrCriteria":"0",
               "startAmount":"30000000000000",
               "endAmount":"30000000000000",
               "recipient":"0xF712B2B35a06016851ADd2f9c43785Ec29e243dE"
            }
         ],
         "totalOriginalConsiderationItems":2,
         "salt":"0x00000000000000000000000000000000000000000000000000000120de4ae00b",
         "conduitKey":"0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
         "counter":"0"
      }
   },
   "approvalsNeeded":[
      {
         "data":"0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001",
         "to":"0x037acA480459Ae361a87b023f189532d80cB6769"
      },
      {
         "data":"0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001",
         "to":"0x229dd7144FEC1008dDdF5fcF779Ec63c3D576aa7"
      }
   ],
   "swapId":"64e7a728c70af13605f2fb11"
}

Here is an example API call, for you to copy and modify:

{
  "offerer": "string",
  "endTime": "Unix Timestamp",
  "chainId": 1,
  "fees": [
      {
      "recipient": "string",
      "basisPoints": number,
    }
  ],
  "offer": [
	{
  	"itemtype": "string",
  	"token": "string",
  	"identifier": "string",
  	"amount": "string"
	}
  ],
  "consideration": [
	{
  	"itemtype": "string",
  	"token": "string",
  	"identifier": "string",
  	"amount": "string"
	}
  

Happy coding!

Last updated