Loopring Dev Docs
Ask or search…
K

Trade NFT

Use this method to understand how to match an NFT maker order with an NFT taker order.

Trade NFT

Private or third party accounts can sign and approve this order
1
// Step 1. getAccount
2
const accInfoC = (
3
await LoopringAPI.exchangeAPI.getAccount({
4
owner: LOOPRING_EXPORTED_ACCOUNT.address,
5
})
6
).accInfo;
7
8
// Step 2. eddsaKeyC
9
const eddsaKeyC = await signatureKeyPairMock(accInfoC);
10
11
// Step 3. apiKey
12
const apiKeyC = (
13
await LoopringAPI.userAPI.getUserApiKey(
14
{
15
accountId: accInfoC.accountId,
16
},
17
eddsaKeyC.sk
18
)
19
).apiKey;
20
// NFT Trade
21
const response = await LoopringAPI.userAPI.submitNFTTrade({
22
request: {
23
maker: {
24
...mockData.makerOrder,
25
eddsaSignature: mockData.makerOrderEddsaSignature,
26
},
27
makerFeeBips: 1000,
28
taker: {
29
...mockData.takerOrder,
30
eddsaSignature: mockData.takerOrderEddsaSignature,
31
},
32
takerFeeBips: 100,
33
},
34
web3,
35
chainId: sdk.ChainId.GOERLI,
36
walletType: sdk.ConnectorNames.Unknown,
37
apiKey: apiKeyC,
38
eddsaKey: eddsaKeyC.sk,
39
});
40
41
console.log(response);

MockOrder

Validate NFT Order please read Validate NFT Order
1
// Step 1. getAccount
2
const accInfo = (
3
await LoopringAPI.exchangeAPI.getAccount({
4
owner: LOOPRING_EXPORTED_ACCOUNT.address,
5
})
6
).accInfo;
7
const accInfo2 = (
8
await LoopringAPI.exchangeAPI.getAccount({
9
owner: LOOPRING_EXPORTED_ACCOUNT.address2,
10
})
11
).accInfo;
12
// Step 2. eddsaKey
13
const eddsaKey = await signatureKeyPairMock(accInfo);
14
const eddsaKey2 = await signatureKeyPairMock(accInfo2, web3_2);
15
// Step 3. apiKey
16
const apiKey = (
17
await LoopringAPI.userAPI.getUserApiKey(
18
{
19
accountId: accInfo.accountId,
20
},
21
eddsaKey.sk
22
)
23
).apiKey;
24
const apiKey2 = (
25
await LoopringAPI.userAPI.getUserApiKey(
26
{
27
accountId: accInfo2.accountId,
28
},
29
eddsaKey2.sk
30
)
31
).apiKey;
32
33
// Step 4. storageId
34
const storageId = await LoopringAPI.userAPI.getNextStorageId(
35
{
36
accountId: accInfo.accountId,
37
sellTokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId,
38
},
39
apiKey
40
);
41
const storageId2 = await LoopringAPI.userAPI.getNextStorageId(
42
{
43
accountId: accInfo2.accountId,
44
sellTokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
45
},
46
apiKey2
47
);
48
// Step 5. generate Order, please read validateNFTOrder
49
const makerOrder: sdk.NFTOrderRequestV3 = {
50
exchange: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
51
accountId: accInfo.accountId,
52
storageId: storageId.orderId,
53
sellToken: {
54
tokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId,
55
nftData: LOOPRING_EXPORTED_ACCOUNT.nftData,
56
amount: "1",
57
},
58
buyToken: {
59
tokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
60
amount: LOOPRING_EXPORTED_ACCOUNT.tradeLRCValue.toString(),
61
},
62
allOrNone: false,
63
fillAmountBOrS: false,
64
validUntil: LOOPRING_EXPORTED_ACCOUNT.validUntil,
65
maxFeeBips: 1000,
66
};
67
const makerOrderEddsaSignature = sdk.get_EddsaSig_NFT_Order(
68
makerOrder,
69
eddsaKey.sk
70
);
71
72
const takerOrder: sdk.NFTOrderRequestV3 = {
73
exchange: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
74
accountId: accInfo2.accountId,
75
storageId: storageId2.orderId,
76
sellToken: {
77
tokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
78
amount: LOOPRING_EXPORTED_ACCOUNT.tradeLRCValue.toString(),
79
},
80
buyToken: {
81
tokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId,
82
nftData: LOOPRING_EXPORTED_ACCOUNT.nftData,
83
amount: "1",
84
},
85
allOrNone: false,
86
fillAmountBOrS: true,
87
validUntil: LOOPRING_EXPORTED_ACCOUNT.validUntil,
88
maxFeeBips: 100,
89
};
90
const takerOrderEddsaSignature = sdk.get_EddsaSig_NFT_Order(
91
takerOrder,
92
eddsaKey2.sk
93
);
94
95
mockData = {
96
takerOrder,
97
takerOrderEddsaSignature,
98
makerOrder,
99
makerOrderEddsaSignature,
100
makerFeeBips: 1000,
101
maxFeeBips: 100,
102
};