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
  • Mint asset
  • Withdraw NFT to L1
  • Withdraw FT to L1

Was this helpful?

  1. Go & JS SDK Basic Guides

10. Asset Withdrawals

Previous9. Asset TransfersNext11. Full Exit

Last updated 2 years ago

Was this helpful?

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.

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

✅

📚SDK REFERENCE

Example

  • Withdraw NFT with NftId = 6

    1. Initialize the client

    2. Withdraw the NFT

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))
}

Example result

WithdrawNft: {"success":true}

Example

  • Withdraw NFT with NftId = 6

    1. Initialize the client

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

console.log("success: ", 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 nft_id = 48;
const to_address = "0x09E45d6FcF322c4D93E6aFE7076601FF10BA942E";
const res = await sdk.withdrawNft(account_name, account_index, nft_id, to_address);

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

Example result

success: true

Withdraw FT to L1

  • 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

    ✅

📚SDK REFERENCE

Example

  • Withdraw 100000 BNB to L1

    • Initialize client

    • Withdraw 100000 BNB

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))
}

Example result

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

Example

  • Withdraw 100000 BNB to L1

    • Initialize client

    • Withdraw 0.0001 BNB

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);

Example result

tx id: LNwRbx6JwTDcSTt5tEosiD2wO4RGre8VxAu9nWayiGs=

Query current user asset through

Mint asset
WithdrawNft
Withdraw
GetAccountAssetsInfoByAccountName