7. Match Orders

Matching orders is to fill the offers or listings with traders' corresponding actions to buy or sell the NFTs for the transactions to be completed.

Initialize SDK

  • You need to initialize the SDK in order to use it.

Match Orders

  • To select the correct order, please refer to Offers.
  • Parameters needed:
    Parameter usage and meaning
    Required or not
    The account name used to initialize the client
    Specify the asset type used to purchase or sell the NFT
    The asset amount to purchase or sell the NFT
    Select an NFT order that is listed for sale or made an offer by someone
    To buy (false) or sell (true) the target NFT
  • Purchase the NFT with offerId = 31
    1. 1.
      Initialize the client
    2. 2.
      Purchase NFT
package main
import (
func main() {
accountName := "Alice"//Zecrey NFT Marketplace SDK will automatically add the suffix ".zec" to the name
seed := "0x6a1a320d14790f2d9aa9a37769f4833d583a3f7f974fd452a3990aeb0e7a6052" //l2 seed
var offerId int64 = 31 //select a listed NFT
AssetAmount = big.NewInt(1000000000000000000) //the amount used to purchase
isSell := false
c, err := sdk.NewClient(accountName, seed)
if err != nil { panic(err) }
result, err := c.AcceptOffer(offerId, isSell, AssetAmount)//false represents "buy" while true represents "sell"
if err != nil { panic(err) }
data, _ := json.Marshal(result)
Example result
  • Information about the status change of the target order will be returned. Please refer to Offers for the status information.
  • The information returned is all about the target order except for "account_name".
"account_name":"Alice",//User's account name
"payment_asset_amount":"1.000000000000000000",//This corresponds to the relative value of 10^18 of the AssetAmount(1000000)
"status":"2", //Status changed to 2
  • Purchase the NFT with offerId = 31
    1. 1.
      Initialize the client
    2. 2.
      Purchase NFT
With the private key:
import { Client } from "@zecrey/zecrey-legend-js-sdk";
const account_name = "amber1.zec";
const seed = "ee823a72698fd05c70fbdf36ba2ea467d33cf628c94ef030383efcb39581e43f";
const client = new Client(account_name, seed);
await client.initialize();
const offer_id = 31;
const res = await client.acceptOffer(offer_id);
console.log("offer id: ", res);
With the wallet:
import { SDK } from "@zecrey/zecrey-legend-js-sdk";
const sdk = new SDK();
await sdk.initial();
const account_name = "Alice.zec"; // sender's account name
const account_index = 14; // sender's account index
const offer_id = 31;
const res = await sdk.acceptOffer(account_name, account_index, offer_id);
console.log("offer id: ", res);
Example result
offer id: 3