Zecrey
  • Introduction
  • Zecrey Onepager
  • Announcements
    • Zecrey Public Testnet Announcement
    • Zecrey Testnet Beta Internal Test Announcement
    • Zecrey Ambassador Program Annoucement
  • Go & JS SDK Basic Guides
    • 1. Install and Initialize
    • 2. Get Data
    • 3. SDK Signature
    • 4. Register Users
    • 5. Mint Assets
    • 6. Creating Orders
    • 7. Match Orders
    • 8. Asset Deposits
    • 9. Asset Transfers
    • 10. Asset Withdrawals
    • 11. Full Exit
    • 12. Demo of SDK Calling
  • Education
    • Zecrey Video Guide
    • Concepts Explained
      • Crypto Knowledge
        • Layer 1 (L1)
        • Layer 2 (L2)
        • ZK-Rollup
        • Gas Fee
        • NFT
      • Zecrey Basics
        • Multi-chain asset management
        • Zecrey L1 wallet
        • Zecrey Legend L2 wallet
        • Zecrey Zero L2 wallet
        • Deposit
        • Withdraw
        • Zecrey DEX
      • The State of Transactions
    • Get Started
      • How to import an account?
      • How to create a new account?
      • How to receive and send assets with QR code?
      • How to export the private key?
      • How to export the recovery phrase?
      • How to use Zecrey NFT Marketplace?
      • How to adjust the gas fee?
      • How to check my transaction record?
      • How to manage my contacts?
      • How to set the language?
      • How to give feedback?
    • FAQs
  • Product Handbook
    • Zecrey Products Introduction
    • Set up your Zecrey Wallet
      • Download and Install Zecrey
      • Create a New Wallet
      • Import an Existing Wallet with Mnemonic
      • Claim Test Tokens for Testnet
      • Testing Requirements
      • Rewards for Phase II Testnet
    • Zecrey L1 Wallet
      • Multi-chain Assets Management
      • L1 Transfer
      • Deposit
      • L1 NFT Management
        • View NFT Assets
        • L1 NFT Transfer
        • NFT Deposit
    • Zecrey Legend L2
      • L2 Account Registration
      • L2 Transfer
      • Withdraw
    • Zecrey NFT Marketplace
      • Explore NFT Marketplace
      • Connect Zecrey Extension to NFT Marketplace
      • Create NFT Collection
      • Mint NFT
      • Buy NFT
      • Sell NFT
      • Transfer NFT
      • Withdraw NFT
      • View NFT Assets
      • Manage NFT Transactions
Powered by GitBook
On this page
  • Initialize SDK
  • Match Orders

Was this helpful?

  1. Go & JS SDK Basic Guides

7. Match Orders

Previous6. Creating OrdersNext8. Asset Deposits

Last updated 2 years ago

Was this helpful?

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 .

  • Parameters needed:

    Parameter

    Parameter usage and meaning

    Required or not

    accountName

    The account name used to initialize the client

    ✅

    assetType

    Specify the asset type used to purchase or sell the NFT

    ✅

    AssetAmount

    The asset amount to purchase or sell the NFT

    ✅

    offerId

    Select an NFT order that is listed for sale or made an offer by someone

    ✅

    isSell

    To buy (false) or sell (true) the target NFT

    ✅

📚SDK REFERENCE

Example:

  • Purchase the NFT with offerId = 31

    1. Initialize the client

    2. Purchase NFT

package main

import (
   "fmt"
   "github.com/Zecrey-Labs/zecrey-marketplace-go-sdk/sdk"
)


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)
    fmt.Println(string(data))
}

Example result

  • The information returned is all about the target order except for "account_name".


{
    "offer":{
        "id":31,
        "account_name":"Alice",//User's account name
        "direction":"1",
        "asset_id":241,
        "payment_asset_id":0,
        "payment_asset_amount":"1.000000000000000000",//This corresponds to the relative value of 10^18 of the AssetAmount(1000000)
        "status":"2", //Status changed to 2
        "signature":"{\"Type\":1,\"OfferId\":1,\"AccountIndex\":3,\"NftIndex\":247,\"AssetId\":0,\"AssetAmount\":1000000000000000000,\"ListedAt\":1667875678292,\"ExpiredAt\":1668350875000,\"TreasuryRate\":30,\"Sig\":\"kpaBoImpjmeI+PlOzkcCr7Tquf16qtriprOUUy3E1JUDjwcttXut8GEu6UV/H4dtJvnqKyD6FwK08hqv0vO67A==\"}",
        "expired_at":1668350875000,
        "created_at":1667875678
    }
}

Example:

  • Purchase the NFT with offerId = 31

    1. Initialize the client

    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

Information about the status change of the target order will be returned. Please refer to for the status information.

Offers
AcceptOffer
Offers