8. Asset Deposits

  • Users are able to deposit assets from L1 to L2 in Zecrey.

Initialize SDK

  • You will need to initialize the SDK in order to use it.

Deposit NFT to L2

  • 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

    privateKey

    Since this transaction involves L1, the private key of user's L1 account is needed to sign the transaction

    nftL1Address

    The corresponding L1 address of the NFT

    nftIndex

    The unique ID of NFT in L1

📚SDK REFERENCE

Example

  • Deposit the NFT with nftIndex = 511

    • Initialize client

    • Deposit the NFT with nftIndex = 511

package main

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


func main() {
    var nftIndex int64 = 511
    accountName := "Bob"
    seed := "17673b9a9fdec6dc90c7cc1eb1c939134dfb659d2f08edbe071e5c45f343d008"
    privateKey := "0xe94a8b4ddd33b2865asadfasda0c3e3276007ece8f114a47a4e9581ec3567"
    nftL1Address := common.HexToAddress("0x805e286D05388911s41a0E3c7b9713415607c72")
    c, err := NewClient(accountName, seed)
    if err != nil {
       t.Fatal(err)
    }
    depositNftTransaction, err := c.DepositNft(accountName, privateKey, nftL1Address, nftIndex)
    if err != nil {
       t.Fatal(err)
    }
    fmt.Println("tx hash: ",depositNftTransaction.Hash())
}

Example Result

tx hash: 0x832b75753c073b29a11431386f2faa744ced1c95603e8ea30e4aa5fd7ca3d14dgolang

Deposit FT to L2

  • 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

    privateKey

    Since this transaction involves L1, the private key of user's L1 account is needed to sign the transaction

    AssetId

    Token ID

  • Token information

    Token

    Token ID

    Parameter

    BNB

    0

    sdk.BNBAssetId

    LEG

    1

    sdk.LEGAssetId

    REY

    2

    sdk.REYAssetId

📚SDK REFERENCE

Example

  • Deposit 10000 BNB to L2

    • Initialize client

    • Deposit

      1. For BEP20 token, you need to import the token address

package main

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


func main() {
    var nftId int64 = 6
    accountName := "Bob"
    seed := "17673b9a9fdec6dc90c7cc1eb1c939134dfb659d2f08edbe071e5c45f343d008"
    privateKey := "0xe94a8b4ddd33b2865asadfasda0c3e3276007ece8f114a47a4e9581ec3567"
    var assetAmount int64 = 10000
    var tokenAddress  = common.HexToAddress("")
    c, err := NewClient(accountName, seed)
    if err != nil { panic(err) }
    
    depositBnbTransaction, err := c.Deposit(accountName, privateKey, sdk.BNBAssetId, assetAmount, tokenAddress)
    if err != nil { panic(err) }
    
    fmt.Println("tx hash:",depositBnbTransaction.Hash())
}

Example result

tx hash: 0x0f20b7cf4f6526b7d67efba10c9e14b0c093eb9c50c7ebd8190413bc0b4c6dd6

Last updated