Public API Documentation

Public API Docs: https://apenft.io/swagger/index.html

API Usage

APENFT provides a user-friendly interfaces with improved usability and allow users to call these APIs to interact with the platform. API services are currently available on the MainNet and Shasta.

Instructions

  1. The postOrder interface is needed to create a SellOrder. You need to input many parameters in the postOrder interface, and the parameters can be generated via the hashOrder interface. Among the parameters returned by the hashOrder interface, the three parameters — r, s, and v need to be generated by using a local signature.
    Most of the parameters for the BuyOrder are the same as those in the SellOrder, with just a few needing adjustments. Please refer to Create BuyOrder for details.

  2. Use the queryOrder interface to query all orders in the collection.

hashOrder

Call the hashOrder interface to generate parameters to be input into the postOrder interface.

Request

  1. Interface function: generate input parameters of the postOrder interface;

  2. Request method:POST

  3. Request address (Test on Shasta): http://ele-testnet.apenft.io/openapi/v1/hashOrder

Example:

{
  "basePrice": "100000000",
  "expirationTime": "1653124380",
  "listingTime": "1650459847",
  "maker": "TLmvi4E7zxSsmQ2NvzC41pS9U7j8NuKAay",
  "paymentToken": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "quantity": "1",
  "salt": "61218070018688938873881537500924780693002681754850341064655765197729684511320",
  "schema": "ERC721",
  "side": 1,
  "taker": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "target": "TZC7kx5xCNZuN34ooLt13Zx4iZn3mMgkWv",
  "tokenId": "2"
}

Parameters explained:

ParamsDescriptions
basePriceThe listing price, token is specified by parameter paymentToken. For example, paymentToken is T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb, for basePrice 1,000,000 means 1 TRX
expirationTimeTimestamp for order expiration. Ten digits long, e.g. 1653124380.
listingTimeTimestamp for listing time. Ten digits long, e.g., 1650459847.
makerSeller's wallet address, in base58 format.
paymentTokenToken Contract Address, e.g., T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX
quantityThe number of NFTs
saltA string of random numbers with a length of 77 digits, e.g., 76431802940535634443859288223886227759190472848754102518674791180720213667853; 0 cannot be used as the initial character
schemaSet the value as ERC721 or ERC1155, currently supporting ERC721
sideBuy/sell order identifier— set the value at 0 for buy orders, and 1 for sell orders.
takerBuyer's wallet address, in base58 format. If buyer is specified, taker's value should be buyer's wallet address. If no buyer is specified, taker's value is 0 address.
targetNFT collection address
tokenIdAn NFT's Token ID in a collection

Response

Example:

{
    "code": 200,
    "data": {
        "id": 0,
        "createdDate": "2022-04-20T13:04:07Z",
        "closingDate": "2022-05-21T09:13:00Z",
        "expirationTime": 1653124380,
        "listingTime": 1650459847,
        "closedTime": 1653124380,
        "orderHash": "0xdb57bc38045d7daadda5dcfef8e20cbd3a3d71100030a862c7e6e913134b99de",
        "metadata": {
            "asset": {
                "id": "2",
                "address": "TZC7kx5xCNZuN34ooLt13Zx4iZn3mMgkWv"
            },
            "schema": "ERC721"
        },
        "exchange": "TYnuR3ripQNZUYUvjkjzbwQ48zHKdAtzis",
        "maker": "TLmvi3E7zxSsmQ3NvzC41pS9U7j8NuKAry",
        "taker": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
        "makerRelayerFee": "0",
        "takerRelayerFee": "0",
        "makerProtocolFee": "0",
        "takerProtocolFee": "0",
        "makerReferrerFee": "",
        "feeMethod": 1,
        "feeRecipient": "TUheU3xYaf36bdi8PgD7eKqGX4dgz2qyv9",
        "side": 1,
        "saleKind": 0,
        "target": "TZC7kx5xCNZuN34ooLt13Zx4iZn3mMgkWv",
        "dataToCall": "0x23b872dd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002",
        "replacementPattern": "0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000",
        "staticTarget": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
        "staticExtradata": "0x",
        "paymentToken": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
        "basePrice": "100000000",
        "extra": "0",
        "englishAuctionReservePrice": "",
        "orderType": 0,
        "quantity": "1",
        "salt": "61218070018688938873881537500924780693002681754850341064655765197729684511320",
        "v": 0,
        "r": "",
        "s": "",
        "approvedOnChain": false,
        "cancelled": false,
        "finalized": false
    },
    "msg": "success"
}

Parameters explained:
Focus on the input parameters of the postOrder interface.

ParamsDescriptions
basePriceThe listing price is denominated in wei. 1,000,000 = 1 TRX
dataToCallEncoded data when making a transfer
englishAuctionReservePriceThe reserve price in an English auction. Leave the value blank ""
exchangeAPENFTTExchange contract address
expirationTimeOrder expiration time. Ten digits long, e.g., 1653124380
extraExtra auction parameter, set the value at 0
feeMethodFee method, set the value at 1
feeRecipientAddress for the royalty payment, designated by the project team (creator)
hashThe hash value of an order
listingTimeTime of listing. Ten digits long, e.g., 1650459847.
makerSeller's wallet address, in base58 format.
makerProtocolFeeAPENFT service fee (paid by the seller to the platform)
makerRelayerFeeAuthor royalty (paid by the seller to the creator)
metadataThe metadata of an NFT, e.g.
{“asset”:
{“id”: “2”, “address”: “TZC7kx6xCNZuN38ooLt13Zx4iZn3mMgkWv”}, “schema”: “ERC721”
}
paymentTokenTokens used for order payment, zero-address: T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX
quantityThe number of NFTs
rThe first 32 bytes of the local signature
sThe 32 bytes after "r" in the local signature
vLocal signature information, set the value at 27 or 28
replacementPatternThe replacement pattern for dataToCall
saleKindSelling method, set the value at 0 (sell at a "fixed price")
saltA string of random numbers with a length of 77 digits, e.g., 76431802940535634443859288223886227759190472848754102518674791180720213667853; 0 cannot be used as the initial character
sideBuy/sell order identifier. Set the value at 0 for a buy order, and 1 for a sell order.
staticExtraDataExtra parameter for an English auction, set the value as "0x"
staticTargetSet the extra parameter value as zero address for fixed-priced orders
takerBuyer's wallet address, in base58 format
takerProtocolFeeAPENFT service fee (paid by the buyer to the platform)
takerRelayerFeeAuthor royalty (paid by the buyer to the creator)
targetNFT collection address

postOrder

Request

  1. Interface function: place orders

  2. Request method: POST

3.Request address (Test on Shasta): http://ele-testnet.apenft.io/openapi/v1/postOrder

Example:

{
  "basePrice": "1000000",
  "dataToCall": "0x23b872dd000000000000000000000000a104d1b682f1068cc9e13e943c09b2439a1a23a6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c6",
  "englishAuctionReservePrice": "0",
  "exchange": "TYnuR3ripQNZUY3vjk7zbwQ48zHKdAtzis",
  "expirationTime": "1650459847",
  "extra": "0",
  "feeRecipient": "TWhpdixJek7oTWiSgiw1vB9d6wakv5Ntac",
  "hash": "0x01c3c19d75be520569b81c50c7315e0b62b05297afdd31f5fe364370c3ee5696",
  "listingTime": "1650459847",
  "maker": "TQebZnbcfpwwPaEmyQt0X9EpV5k2Mq88ui",
  "makerRelayerFee": "0",
  "metadata": {
    "asset": {
      "address": "TQ9Rxiv2H3JeDC4zW6GQ6ZAHC5xCmacBsV",
      "id": "2"
    },
    "schema": "ERC721"
  },
  "paymentToken": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "quantity": "1",
  "r": "0xdad85ebf01d57f0414ed68b674f24a7b06407bf68d311acdf6daf50ec9c9864d",
  "replacementPattern": "0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000",
  "s": "0x59ac49422662d102719823735fe9f1e3f793298689e60beca34980d431f66d49",
  "saleKind": 0,
  "salt": "23568344558784782936679170265198715627992689485756827974971615835940603257706",
  "side": 1,
  "staticExtraData": "0x",
  "staticTarget": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "taker": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "takerRelayerFee": "0",
  "target": "TQ9Rxiv2HzJeDC4zWacG8ZAHC5xCmacBsV",
  "v": 0
}

Descriptions of parameters are the same as those of the hashOrder interface

Response

Example:

{
   "code":200,
   "data":{
      "id":7610,
      "createdDate":"2022-05-07T07:36:56Z",
      "closingDate":"2022-05-31T16:00:00Z",
      "expirationTime":1654012800,
      "listingTime":1651909016,
      "closedTime":1654012800,
      "orderHash":"0x46fa10e317e99f7a95b128a55ad3aa1a419db73aa907ada9175ec897c2824666",
      "metadata":{
         "asset":{
            "id":"454",
            "address":"TQ9Rxiv2HzJeDC4zW6GQ6ZAHC5xCmacBsV"
         },
         "schema":"ERC721"
      },
      "exchange":"TYnuR3ripQNZUYUvjkjzbwQ48zHKdAtzis",
      "maker":"TQebZnbcfpwwPaEmy3trX2EpV5k2Mq63yv",
      "taker":"TLmvi3E7zxSsmQ2NvzC417S9Ucj3NuKAry",
      "makerRelayerFee":"0",
      "takerRelayerFee":"0",
      "makerProtocolFee":"0",
      "takerProtocolFee":"0",
      "makerReferrerFee":"",
      "feeMethod":1,
      "feeRecipient":"TWhpdixJek7oTW1Sgi81vBgd6wakv5NtbJ",
      "side":1,
      "saleKind":0,
      "target":"TQ9Rxiv2HzJeDC4zW6GQ6ZAHC5xCmacBsV",
      "dataToCall":"0x23b872dd000000000000000000000000a104d1b682f1068cc9e13e943c09b2439a1a23a6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c6",
      "replacementPattern":"0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000",
      "staticTarget":"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
      "staticExtradata":"0x",
      "paymentToken":"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
      "basePrice":"162000000",
      "extra":"0",
      "englishAuctionReservePrice":"",
      "orderType":0,
      "quantity":"1",
      "salt":"51888723336519951392513597205404565463233163782163691344827598215514513419667",
      "v":28,
      "r":"0xae98743c81b5d43d6e035a5de9446cb2c3ef16afe0f9f10065982dda0060654e",
      "s":"0x04e68cd4855d742180d00ed02353bc5d77748c2e0601251a8118978796612341",
      "approvedOnChain":false,
      "cancelled":false,
      "finalized":false
   },
   "msg":"success"
}

Parameters explained:

ParamsDescriptions
codeReturn code; 200 for success, and 400 for failure
dataOrder information
msgDescription of the returned result

queryOrder

Request

  1. Interface function: query platform orders

  2. Request method: GET

  3. Request address (Test on Shasta): http://ele-testnet.apenft.io/openapi/v1/queryOrder

Example:
https://ele-testnet.apenft.io/openapi/v1/queryOrders?assetContract=THjYwnDDN6aYxrzKb88CSMTEYjBuHpoYxS&assetTokenId=34824

Parameters explained:

ParamsDescriptions
assetContractThe contract address of the collection being queried
assetTokenIdThe ID of the NFT being queried
saleKindOrder type. 0 for fixed prices, 1 for Dutch auction, and 2 for English auction. Default setting: 0
side0 for a buyer order, and 1 for a seller order
makerThe result is returned by filtering the seller's wallet address
takerThe result is returned by filtering the buyer's wallet address. For orders without specifying a buyer, the taker address is zero address: T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb
paymentTokenThe contract address corresponding to the token used for order payment
listedBeforeTimestamp. Only orders earlier than this time to be displayed in the returned results
listedAfterTimestamp. Only orders later than this time to be displayed in the returned results
orderBySorting returned results. Options: NEWEST, PRICE_ASC, PRICE_DESC, or EXPIRING_SOON

NEWEST: Sorting by the value of listingTime
PRICE_ASC: Sorting by the value of basePrice in ascending order
PRICE_ASC: Sorting by the value of basePrice in descending order
EXPIRING_SOON: Sorting by the value of expirationTime in ascending order

Default setting: NEWEST
limitThe number of returned orders displayed per page. Default: 20, maximum: 50
offsetThe offset of pages. Default: 1

Response

Example:

{
    "code": 200,
    "msg": "success",
    "total": 1,
    "page_num": 1,
    "data": [
        {
            "id": 23353,
            "createdDate": "2022-05-29T03:07:45Z",
            "closingDate": "2022-08-27T03:09:00Z",
            "expirationTime": 1661569740,
            "listingTime": 1653793665,
            "closedTime": 1661569740,
            "orderHash": "0x5e1ecc7dd235ea31e94c5658bd52532247eb4fec0a60e4ef8c0152528623c139",
            "metadata": {
                "asset": {
                    "id": "34824",
                    "address": "THjYwnDDN6aYxrzKb88CSMTEYjBuHpoYxS"
                },
                "schema": "ERC721"
            },
            "exchange": "TQr5axvJzETeHsUiXv6QjBEh1BKH571AZu",
            "maker": "TW1MoE9Sijj1UtxzN4LF94GtoCqvb7F8tD",
            "taker": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
            "makerRelayerFee": "0",
            "takerRelayerFee": "0",
            "makerProtocolFee": "0",
            "takerProtocolFee": "0",
            "makerReferrerFee": "",
            "feeMethod": 1,
            "feeRecipient": "TPyjyZfsYaXStgz2NmAraF1uZcMtkgNan5",
            "side": 0,
            "saleKind": 0,
            "target": "THjYwnDDN6aYxrzKb88CSMTEYjBuHpoYxS",
            "dataToCall": "0x23b872dd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbcab0accf22fde234753e00db4a69f05ff3c48f0000000000000000000000000000000000000000000000000000000000008808",
            "replacementPattern": "0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "staticTarget": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
            "staticExtradata": "0x",
            "paymentToken": "TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn",
            "basePrice": "1000000000000000000",
            "extra": "0",
            "englishAuctionReservePrice": "",
            "orderType": 0,
            "quantity": "1",
            "salt": "15175784119808061584267285266457022051029809268771777750257720208872903835669",
            "v": 27,
            "r": "0x031660a6148c249cc7a73ae3c9e50935997c0304393091eb8fcbbfa6c7214f4a",
            "s": "0x51274aceeec7c16516936d90f7db39b862e70f10f2c246d526a38ff3d43a1e94",
            "approvedOnChain": false,
            "cancelled": false,
            "finalized": false
        }
    ]
}

Descriptions of parameters are the same as those of the hashOrder interface

Generation of local signature

Generating the signature by calling orderSign

const TronWeb = require("tronweb");

const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.shasta.trongrid.io");
const solidityNode = new HttpProvider("https://api.shasta.trongrid.io");
const eventServer = new HttpProvider("https://api.shasta.trongrid.io");

// crate tronWeb
function newTronWeb(privateKey) {
    let tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);
    return tronWeb
}

async function orderSign(orderHash, arg2) {  // orderHash comes from response json of hashOrder
    const tronWeb = newTronWeb(arg2)
    const signature = await tronWeb.trx.sign(orderHash, tronWeb.defaultPrivateKey, true);
    const result = signature.substring(2);
    const r = "0x" + result.substring(0, 64);
    const s = "0x" + result.substring(64, 128);
    const v = parseInt(result.substring(128, 130), 16);// The signature is now comprised of r, s, and v.
    return Promise.resolve({
        r, s, v, signature
    });
}

Create SellOrder

Replace r, s, v in the returned result of hashOrder with r, s, v generated by calling orderSign, then insert the fixed value howToCall:0 into the returned data to generate a sellOrder.

Example:

{
  "id": 6094,
  "createdDate": "2022-04-27T06:23:53Z",
  "closingDate": "2022-04-30T16:00:00Z",
  "expirationTime": 1651334400,
  "listingTime": 1651040633,
  "closedTime": 1651334400,
  "orderHash": "0x79d2371a55b46b952ea6c5ce44e17e6cc1fb840560d80e0d561ea336e837947a",
  "metadata": {
    "asset": {
      "id": "2",
      "address": "TVQ7DEJ6U7EdgByLwHdSu4Sfdc9TN1BxA3"
    },
    "schema": "ERC721"
  },
  "exchange": "TYnuR3ripQNZUYUvjkjzbwQ48zHKdAtzis",
  "maker": "TQbbqHRid8Fmg8WjSd779APyUB2Ynbacif",
  "taker": "TPKUDRkQZ2PRiHw1KkcG1qgZxJM7s7Mqui",
  "makerRelayerFee": "0",
  "takerRelayerFee": "0",
  "makerProtocolFee": "0",
  "takerProtocolFee": "0",
  "makerReferrerFee": "",
  "feeMethod": 1,
  "feeRecipient": "TUheU3xYaf36bdi8la37eKqGX4dgz2qyv9",
  "side": 1,
  "saleKind": 0,
  "target": "TVQ7DEJ6U7EdgByLwHdSu4Sfdc9TN1BxA3",
  "dataToCall": "0x23b872dd0000000000000000000000009bf228a9de562f130a9259857ce408073f8e8c7b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002",
  "replacementPattern": "0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000",
  "staticTarget": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "staticExtradata": "0x",
  "paymentToken": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
  "basePrice": "100000000",
  "extra": "0",
  "englishAuctionReservePrice": "",
  "orderType": 0,
  "quantity": "1",
  "salt": "76431802940535634443859288223886227759190472848754102518674791180720213667853",
  "v": 27,
  "r": "0x6566a41e4d1f2e3e0617ff50d760f7d3cdcbca4d664f0a646f41ec6cd778db64",
  "s": "0x7da36ee7d9d6245a26d0a65be378943603f74b2cc57b3895415e198d490c877c",
  "approvedOnChain": false,
  "cancelled": false,
  "finalized": false,
  "howToCall": 0
}

Create BuyOrder

Create a dataToCall for buyOrder

Input the buyer address and the NFT's tokenID and call encodeBuyDatatocall to create a dataToCall for buyOrder.

function encodeBuyDatatocall(buyerAddressStr, tokenId) {
    const from = '0000000000000000000000000000000000000000000000000000000000000000';
    const to = formatHex32Byte(buyerAddressStr);
    const id = formatNumber(tokenId);
    const dataToCall = '0x23b872dd' + from + to + id;
    // console.log("dataToCall:" + dataToCall);
    return dataToCall;
}

function formatHex32Byte(hexStr) {
    let str = hexStr.toLowerCase().startsWith("41") ? hexStr.substring(2).toLowerCase() : hexStr.toLowerCase();
    let zero = '';
    for (let i = str.length; i < 64; i++) {
        zero += '0';
    }
    return zero + str;
}

function formatNumber(num) {
    const hexStr = new BigNumber(num).toString(16);
    return formatHex32Byte(hexStr);
}

Create a buyOrder based on the sellOrder

Modify a sellOrder to create a buyOrder:

  • Set maker of the buyOrder to taker of the sellOrder
  • Set taker of the buyOrder to maker of the sellOrder
  • Set side of the buyOrder to 0
  • Set feeRecipient of the buyOrder to zero address
  • Set replacementPattern of the buyOrder to the other replacement pattern:
    when the sellOrder's replacementPattern is pattern one, the buyOrder's replacementPattern will be pattern two, and vice versa.
Pattern One: 0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000

Pattern Two: 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000