> For the complete documentation index, see [llms.txt](https://docs.zecrey.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zecrey.com/go-and-js-sdk-basic-guides/10.-asset-withdrawals.md).

# 10. Asset Withdrawals

Users are able to withdraw assets from L2 to L1 in Zecrey.

### Initialize SDK

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

### [Mint asset](https://docs.zecrey.com/go-and-js-sdk-basic-guides/5.-mint-assets)

### Withdraw NFT to L1

* 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 | ✅                    |
| nftId       | The corresponding ID of the NFT to be withdrawn  | ✅                    |

{% hint style="success" %}
&#x20;**📚SDK REFERENCE**

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

{% tabs %}
{% tab title="Golang" %}
**Example**

* Withdraw NFT with `NftId` = 6
  1. Initialize the client
  2. Withdraw the NFT

{% code overflow="wrap" %}

```go
package main

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


func main() {
    var nftId int64 = 6
    accountName := "Bob"
    seed := "17673b9a9fdec6dc90c7cc1eb1c939134dfb659d2f08edbe071e5c45f343d008"
    c, err := sdk.NewClient(accountName, seed) 	 
    if err != nil { panic(err) }
    
    result, err := c.WithdrawNft(nftId)
    if err != nil { panic(err) }
    
    data, _ := json.Marshal(result)
    fmt.Println("WithdrawNft:", string(data))
}
```

{% endcode %}

&#x20; **Example result**

{% code overflow="wrap" %}

```json
WithdrawNft: {"success":true}
```

{% endcode %}
{% endtab %}

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

* Withdraw NFT with `NftId` = 6
  1. Initialize the client
  2. Withdraw the NFT

&#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 nft_id = 48;
const to_address = "0x09E45d6FcF322c4D93E6aFE7076601FF10BA942E";
const res = await client.withdrawNft(nft_id, to_address);

console.log("success: ", res);
```

{% endcode %}

&#x20; 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_id = 48;
const to_address = "0x09E45d6FcF322c4D93E6aFE7076601FF10BA942E";
const res = await sdk.withdrawNft(account_name, account_index, nft_id, to_address);

console.log("success: ", res);
```

{% endcode %}

&#x20; **Example result**

{% code overflow="wrap" %}

```json
success: true
```

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

### Withdraw FT to L1

* Query current user asset through [GetAccountAssetsInfoByAccountName](/go-and-js-sdk-basic-guides/2.-get-data.md#get-account-details-by-account-name)
* Parameters needed:

  | Parameter   | Parameter usage and meaning                      | Requirement |
  | ----------- | ------------------------------------------------ | ----------- |
  | accountName | The account name used to initialize the client   | ✅           |
  | seed        | The user's L2 seed used to initialize the client | ✅           |
  | nftId       | ID of the NFT to be withdrawn                    | ✅           |
  | tol1Address | Specify an L1 address to withdraw                | ✅           |

{% hint style="success" %}

#### 📚SDK REFERENCE

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

{% tabs %}
{% tab title="Golang" %}
**Example**

* Withdraw 100000 BNB to L1
  * Initialize client
  * Withdraw 100000 BNB

{% code overflow="wrap" %}

```javascript
package main

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


func main() {
    seed := "13243b9a9fdec6dc90c7cc1eb1c939134dfb659d2f0asdfas5413213213213213"
    accountName := "bob"
    tol1Address := "0x< a l1 address you want to withdraw>"
    assetAmount := int64(100000)
    c, err := sdk.NewClient(accountName, seed)
    if err != nil { panic(err) }
   
    result, err := c.Withdraw(tol1Address,sdk.BNBAssetId, assetAmount)
    if err != nil { panic(err) }
    
    data, err := json.Marshal(result)
    fmt.Println("Withdraw:", string(data))
}
```

{% endcode %}

**Example result**

{% code overflow="wrap" %}

```json
Withdraw: {"tx_id":"DJIkgT9j2f1uX2xkWR+fJ35Kyg/HDJ4trixtL9CNG/k="}
```

{% endcode %}
{% endtab %}

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

* Withdraw 100000 BNB to L1
  * Initialize client
  * Withdraw 0.0001 BNB

{% 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 asset_id = 0; // BNB
const amount = "100000000000000"; // 0.0001 BNB
const to_address = "0x09E45d6FcF322c4D93E6aFE7076601FF10BA942E";

const res = await client.withdraw(asset_id, amount, to_address);

console.log("tx id: ", res);
```

{% endcode %}

**Example result**

{% code overflow="wrap" %}

```json
tx id: LNwRbx6JwTDcSTt5tEosiD2wO4RGre8VxAu9nWayiGs=
```

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.zecrey.com/go-and-js-sdk-basic-guides/10.-asset-withdrawals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
