# 6. Creating Orders

* Orders are requests to exchange a certain amount of one asset for a different amount of another asset. This typically refers to a listing or an offer in the world of NFTs.

## Where are the orders？

Once an order is created, it will be added to the [Zecrey NFT Marketplace](https://github.com/Zecrey-Labs/zecrey-marketplace/tree/develop). They will be recorded on Zecrey NFT Marketplace to be viewed and available to all participants for trading.

## Zecreymarket SDK

### Initialize SDK

* You need to [initialize the SDK](https://docs.zecrey.com/go-and-js-sdk-basic-guides/1.-install-and-initialize) in order to use it.

### Create a listing

* Parameters needed:

  | Parameter   | Parameter usage and meaning                      | Required or not |
  | ----------- | ------------------------------------------------ | --------------- |
  | accountName | The account name used to initialize the client   | ✅               |
  | seed        | The user's L2 seed used to initialize the client | ✅               |
  | assetType   | Specify the asset type used to purchase the NFT  | ✅               |
  | AssetAmount | The asset amount needed to purchase the NFT      | ✅               |
  | nftId       | Id of the NFT to be sold                         | ✅               |

{% hint style="success" %}
📚**SDK REFERENCE**

* [CreateSellOffer](https://pkg.go.dev/github.com/Zecrey-Labs/zecrey-marketplace-go-sdk@v1.0.5/sdk#Client.CreateSellOffer)
  {% endhint %}

{% tabs %}
{% tab title="Golang" %}
&#x20; **Example**

* Create an order to list the NFT with `NftId` = 14
  1. Initialize the client
  2. Create a listing

{% code overflow="wrap" %}

```go
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" //l2seed
    assetType = 0    //the asset type to purchase the NFT
    AssetAmount = big.NewInt(1000000) //the asset amount needed to purchase the NFT
    nftId = 14
    c, err := sdk.NewClient(accountName, seed) 	 
    if err != nil { panic(err) }
    
    result, err := c.CreateSellOffer(nftId, assetType, AssetAmount)
    if err != nil { panic(err) }
    data, _ := json.Marshal(result)
    fmt.Println("CreateSellOffer:", string(data))
}
```

{% endcode %}

**Example result**

{% code overflow="wrap" %}

```json
CreateSellOffer: 
{
    "offer":{
        "id":21,
        "account_name":"Alice",
        "direction":"1",
        "asset_id":11,
        "payment_asset_id":0,
        "payment_asset_amount":"0.000001000000000000",//This corresponds to the relative value of 10^18 of the AssetAmount(1000000)
        "status":"1",
        "signature":"{\"Type\":1,\"OfferId\":1,\"AccountIndex\":4,\"NftIndex\":14,\"AssetId\":0,\"AssetAmount\":1000000000000,\"ListedAt\":1667963243006,\"ExpiredAt\":1668136043006,\"TreasuryRate\":200,\"Sig\":\"lzpBuJsvntEjcF1e4Y6euAaVCB4LzFWAd2axjKGp3xEAKQB3QcvcgOxgSS54wgVGG1EQNMe1e/Gzg+4Ecxwi+g==\"}",
        "expired_at":1668136043006,
        "created_at":1667963243
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Javascript" %}
**Example**

* Create an order to list the NFT with `NftId` = 14
  1. Initialize the client
  2. Create a listing

With the private key:

{% code overflow="wrap" %}

```javascript
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 nft_index = 14;
const asset_id = 0; // BNB
const asset_amount = "1000000000000000000"; // 1 BNB

const res = await client.createSellOffer(nft_index, asset_id, asset_amount);

console.log(res);
```

{% endcode %}

With the wallet:

{% code overflow="wrap" %}

```javascript
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 nft_index = 14;
const asset_id = 0; // BNB
const asset_amount = "1000000000000000000"; // 1 BNB

const res = await sdk.createSellOffer(account_name, account_index, nft_index, asset_id, asset_amount);

console.log(res);
```

{% endcode %}

&#x20; **Example result**

{% code overflow="wrap" %}

```json
{
    id: 24643,
    signature: "{"Type":1,"OfferId":245,"AccountIndex":4,"NftIndex":7,"AssetId":0,"AssetAmount":1000000000000000000,"ListedAt":1675310419174,"ExpiredAt":1675742417512,"TreasuryRate":200,"Sig":"7obDPs4K25hWF+vY+tXL1I4Y1gmXUcayX34aeQKTJ5AFlQOaug/szcsk3QIweBtGV1oIaM5k+vHoUQUhDjRMQA=="}",
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Make an offer

* Parameters needed:

| Parameter   | Parameter usage and meaning                      | Required vs Optional |
| ----------- | ------------------------------------------------ | -------------------- |
| accountName | The account name used to initialize the client   | ✅                    |
| seed        | The user's L2 seed used to initialize the client | ✅                    |
| assetType   | Specify the asset type used to purchase the NFT  | ✅                    |
| AssetAmount | The asset amount needed to purchase the NFT      | ✅                    |
| nftId       | The Id of the NFT to be purchased                | ✅                    |

{% hint style="success" %}

#### 📚SDK REFERENCE

* [CreateBuyOffer](https://pkg.go.dev/github.com/Zecrey-Labs/zecrey-marketplace-go-sdk@v1.0.5/sdk#Client.CreateBuyOffer)
  {% endhint %}

{% tabs %}
{% tab title="Golang" %}
&#x20;**Example**

* Make an offer to the NFT with `NftId` = 14
  1. Initiate the client
  2. Create an offer

{% code overflow="wrap" %}

```go
package main

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


func main() {
    accountName := "Bob"//Zecrey NFT Marketplace SDK will automatically add the suffix ".zec" to the name
    seed := "17673b9a9fdec6dc90c7cc1eb1c939134dfb659d2f08edbe071e5c45f343d008" //l2seed
    c, err := sdk.NewClient(accountName, seed) 	 
    if err != nil { panic(err) }
    
    assetType = 0    //specify the asset type to purchase the NFT
    AssetAmount = big.NewInt(1000000) //the asset amount needed to purchase the NFT with 1 as the smallest unit of the token type
    nftId = 14
    result, err := c.CreateBuyOffer(nftId, assetType, AssetAmount)
    if err != nil { panic(err) }
    data, _ := json.Marshal(result)
    fmt.Println("CreateBuyOffer:", string(data))
}
```

{% endcode %}

&#x20; **Example result**

{% code overflow="wrap" %}

```json
CreateBuyOffer:
{
    "offer":{
        "id":22,
        "account_name":"Bob",
        "direction":"0",
        "asset_id":14,
        "payment_asset_id":0,
        "payment_asset_amount":"0.000001000000000000",//This corresponds to the relative value of 10^18 of the AssetAmount(1000000)
        "status":"1",
        "signature":"{\"Type\":0,\"OfferId\":2,\"AccountIndex\":2,\"NftIndex\":14,\"AssetId\":0,\"AssetAmount\":1000000000000,\"ListedAt\":1667963545528,\"ExpiredAt\":1668136345528,\"TreasuryRate\":200,\"Sig\":\"XEpxPmmVXYJ2A+YBom4B7pe4Tm+rgvAqkH5MQHO1NaIFby8sgnTlpGpabAx9U7RytUqQc57hOrsFyCzEx4kCbQ==\"}",
        "expired_at":1668136345528,
        "created_at":1667963545
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Javascript" %}
&#x20; **Example**

* Make an offer to the NFT with `NftId` = 14
  1. Initiate the client
  2. Create an offer

With the private key:

{% code overflow="wrap" %}

```javascript
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 nft_index = 14;
const asset_id = 0; // BNB
const asset_amount = "1000000000000000000"; // 1 BNB

const res = await client.createSellOffer(nft_index, asset_id, asset_amount);

console.log(res);
```

{% endcode %}

With the wallet:

{% code overflow="wrap" %}

```javascript
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 nft_index = 14;
const asset_id = 0; // BNB
const asset_amount = "1000000000000000000"; // 1 BNB

const res = await sdk.createSellOffer(account_name, account_index, nft_index, asset_id, asset_amount);

console.log(res);
```

{% endcode %}

**Example result**

{% code overflow="wrap" %}

```json
{
    id: 24643,
    signature: "{"Type":0,"OfferId":245,"AccountIndex":4,"NftIndex":7,"AssetId":0,"AssetAmount":1000000000000000000,"ListedAt":1675310419174,"ExpiredAt":1675742417512,"TreasuryRate":200,"Sig":"7obDPs4K25hWF+vY+tXL1I4Y1gmXUcayX34aeQKTJ5AFlQOaug/szcsk3QIweBtGV1oIaM5k+vHoUQUhDjRMQA=="}",
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Cancel an order

* To cancel a previous offer/listing order, you can use the `cancelOffer` request.

{% hint style="success" %}

#### 📚SDK REFERENCE

* [CancelOffer](https://pkg.go.dev/github.com/Zecrey-Labs/zecrey-marketplace-go-sdk@v1.0.5/sdk#Client.CancelOffer)
  {% endhint %}

{% tabs %}
{% tab title="Golang" %}
&#x20;**Example**

* Cancel offer/order with `offerId` = 22
  1. Initialize the client
  2. Cancel the offer/order

{% code overflow="wrap" %}

```go
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" //l2seed
    OfferId := 22    //View offers/orders through "Get NFT list of offers"
    c, err := sdk.NewClient(accountName, seed) 	 
    if err != nil { panic(err) }
    
    result, err := c.CancelOffer(AssetId, assetType, AssetAmount)
    if err != nil { panic(err) }
    
    data, _ := json.Marshal(result)
    fmt.Println(string(data))
}
```

{% endcode %}

&#x20;**Example result**

{% code overflow="wrap" %}

```json
{
    "offer":{
        "id":22,
        "account_name":"Alice",
        "direction":"0",
        "asset_id":9,
        "payment_asset_id":0,
        "payment_asset_amount":"0.000001000000000000",
        "status":"4",//cancelled
        "signature":"{\"Type\":0,\"OfferId\":2,\"AccountIndex\":2,\"NftIndex\":4,\"AssetId\":0,\"AssetAmount\":1000000000000,\"ListedAt\":1667963545528,\"ExpiredAt\":1668136345528,\"TreasuryRate\":200,\"Sig\":\"XEpxPmmVXYJ2A+YBom4B7pe4Tm+rgvAqkH5MQHO1NaIFby8sgnTlpGpabAx9U7RytUqQc57hOrsFyCzEx4kCbQ==\"}",
        "expired_at":1668136345528,
        "created_at":1667963545
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Javascript" %}
&#x20; **Example**

* Cancel offer/order with `offerId` = 22
  1. Initialize the client
  2. Cancel the offer/order

&#x20; With the private key:

{% code overflow="wrap" %}

```javascript
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 = 24504;
const res = await client.cancelOffer(offer_id);

console.log("offer id: ", res)
```

{% endcode %}

&#x20; With the wallet:

{% code overflow="wrap" %}

```json
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 = 24504;
const res = await sdk.cancelOffer(account_name, account_index, offer_id);

console.log("offer id: ", res)
```

{% endcode %}

&#x20; **Example result**

```
offer id: 24504
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zecrey.com/go-and-js-sdk-basic-guides/6.-creating-orders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
