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.

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}

Withdraw FT to L1

  • Query current user asset through GetAccountAssetsInfoByAccountName

  • 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="}

Last updated