API
API 接口文档
API 主网在线文档:https://apenft.io/swagger/index.html
接口及参数解释
APENFT API 提供用户友好的接口,提高可用性,供用户调用与平台交互。API 服务目前适用于主网和 Shasta 测试网。
使用步骤说明
-
生成卖方订单信息 SellOrder 需要使用 postOrder 接口。postOrder 接口输入参数较多,可以通过 hashOrder 接口生成。hashOrder 接口返回参数中,r,s,v 这 3 个参数需要使用 生成本地签名信息 生成。
买方订单信息 BuyOrder 大部分参数与 SellOrder 相同,部分参数需要修改。修改方法参照 生成 BuyOrder 章节。 -
查询合集的所有订单使用 queryOrder 接口
hashOrder
请求
-
接口功能:生成 postOrder 接口的入参
-
请求方式:POST
-
请求地址(以测试网为例):http://ele-testnet.apenft.io/openapi/v1/hashOrder
请求示例:
{
"basePrice": "100000000",
"expirationTime": "1653124380",
"listingTime": "1650459847",
"maker": "TLmvi4E7zxSsmQ2NvzC41pS9U7j8NuKAay",
"paymentToken": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
"quantity": "1",
"salt": "61218070018688938873881537500924780693002681754850341064655765197729684511320",
"schema": "ERC721",
"side": 1,
"taker": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
"target": "TZC7kx5xCNZuN34ooLt13Zx4iZn3mMgkWv",
"tokenId": "2"
}
参数说明:
参数 | 描述 |
---|---|
basePrice | 挂单价格,代币种类由 paymentToken 参数指定。如 paymentToken 取值为 T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb 时, basePrice 取值 1000000 代表 1 TRX |
expirationTime | 订单过期时间戳,长度为10位,如 1653124380 |
listingTime | 上架时间戳,长度为10位,如 1650459847 |
maker | 卖方钱包地址,base58格式 |
paymentToken | 代币合约地址,如 T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb, 为 TRX |
quantity | NFT 数量 |
salt | 长度为 77 位的随机数字组成的字符串,例如 76431802940535634443859288223886227759190472848754102518674791180720213667853,不能以 0 作为第一位字符 |
schema | 取值为 ERC721, ERC1155,目前支持 ERC721 |
side | 订单买卖标识,取值为0时是买单,取值为1时是卖单 |
taker | 买方钱包地址,base58格式。指定买方时,taker取值为买方钱包地址。不指定买方时,taker取值为0地址 |
target | NFT 所在合集地址 |
tokenId | NFT 在合集中的 ID |
响应
响应示例
{
"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"
}
参数说明
只需关注作为 postOrder 接口输入的参数即可
参数 | 描述 |
---|---|
basePrice | 挂单价格,单位是 wei,如 1000000 代表 1 trx |
dataToCall | 转账时的编码数据 |
englishAuctionReservePrice | 英式拍卖保留价格,取空值 "" 即可 |
exchange | APENFTExchange 合约地址 |
expirationTime | 订单过期时间,长度为10位,如 1653124380 |
extra | 拍卖额外参数,取值为 0 |
feeMethod | 费⽤⽅法 ,取值为 1 |
feeRecipient | 版税收费地址,为项目方指定地址 |
hash | 订单的hash值 |
listingTime | 上架时间,长度为10位,如 1650459847 |
maker | 卖方钱包地址,base58格式 |
makerProtocolFee | 卖方平台费率 |
makerRelayerFee | 卖方版税费率 |
metadata | NFT 元数据,例如 {“asset”: {“id”: “2”, “address”: “TZC7kx6xCNZuN38ooLt13Zx4iZn3mMgkWv”}, “schema”: “ERC721” } |
paymentToken | ⽀付订单币种,zero-address: T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb 代表币种为 TRX |
quantity | NFT 数量 |
r | 本地生成签名信息前32 bytes |
s | 本地生成签名信息r之后的32 bytes |
v | 本地生成签名信息,取值为27或28 |
replacementPattern | dataToCall 的替换模式 |
saleKind | 售卖方式,取值为 0 (以“固定价格”方式售卖) |
salt | 长度为 77 位的随机数字组成的字符串,例如 76431802940535634443859288223886227759190472848754102518674791180720213667853,不能以 0 作为第一位字符 |
side | 订单买卖标识,取值为0时是买单,取值为1时是卖单 |
staticExtraData | 英拍额外参数,取值为 “0x” |
staticTarget | 英拍额外参数,固定价格订单,该参数取值为 0 地址 |
taker | 买方钱包地址,base58格式 |
takerProtocolFee | 买方平台费率 |
takerRelayerFee | 买方版税费率 |
target | NFT 所在合集地址 |
postOrder
请求
-
接口功能:下单
-
请求方式:POST
-
请求地址(以测试网为例):http://ele-testnet.apenft.io/openapi/v1/postOrder
请求示例:
{
"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
}
参数说明同 hashOrder 接口返回参数说明
响应
响应示例:
{
"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"
}
参数说明
参数 | 描述 |
---|---|
code | 返回码,200 代表成功,400 代表失败 |
data | 订单信息 |
msg | 返回结果描述 |
queryOrder
-
接口功能:查询平台订单
-
请求方式:GET
-
请求地址(以测试网为例):http://ele-testnet.apenft.io/openapi/v1/queryOrder
请求
参数说明:
参数 | 描述 |
---|---|
assetContract | 被查询合集对应的合约地址 |
assetTokenId | 被查询 NFT 对应的 ID |
saleKind | 订单类型,0 为固定价格订单,1 为荷式拍卖,2 为英式拍卖。默认值为 0 |
side | 0 是买方订单, 1 是卖方订单 |
maker | 根据卖方钱包地址过滤返回结果 |
taker | 根据买方钱包地址过滤返回结果,不指定买方的订单,taker 地址为 0 地址:T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb |
paymentToken | 订单币种对应的合约地址 |
listedBefore | 时间戳,只有早于这个时间点的订单才会显示在返回结果中 |
listedAfter | 时间戳,只有晚于这个时间点的订单才会显示在返回结果中 |
orderBy | 返回结果排序,可选值:NEWEST, PRICE_ASC, PRICE_DESC, EXPIRING_SOON NEWEST: 按 listingTime 字段值排序 PRICE_ASC:按 basePrice 字段值升序排序 PRICE_DESC:按 basePrice 字段值降序排序 EXPIRING_SOON:按 expirationTime 字段值升序排序 默认值为 NEWEST |
limit | 每页展示的返回订单数量,默认值为 20,最大值为 50 |
offset | 分页数,默认值为 1 |
响应
响应示例
{
"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
}
]
}
关键参数说明同 hashOrder 接口返回参数说明
生成本地签名信息
调用 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
});
}
生成 SellOrder
将 hashOrder 返回报文中的 r, s, v 替换为 orderSign 生成的 r, s, v。再将固定值howToCall:0, 插⼊返回的data中 即可⽣成sell订单。
示例:
{
"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
}
生成 BuyOrder
生成买单 dataToCall
⼊参为买家 address 及NFT资产 tokenID,调⽤ encodeBuyDatatocall ⽅法,⽣成买单 dataToCall。
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);
}
根据卖单信息生成买单
修改卖单以生成买单:
- 买单 maker 取值为卖单 taker
- 买单 taker 取值为卖单 maker
- 买单 side 取值为 0
- 买单 feeRecipient 取值为 0 地址
- 买单 replacementPattern 取值为替换模式的另一个值:
卖单中 replacementPattern 取值为模式一时,买单中 replacementPattern 取值为模式二,反之亦然。
模式一:0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000
模式二:0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Updated over 1 year ago