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
  • Deposit NFT to L2
  • Deposit FT to L2

Was this helpful?

  1. Go & JS SDK Basic Guides

8. Asset Deposits

Previous7. Match OrdersNext9. Asset Transfers

Last updated 2 years ago

Was this helpful?

  • 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

Example

Advance approval for NFT is require

import { SDK } from "@zecrey/zecrey-legend-js-sdk";

const sdk = new SDK();
await sdk.initial();

const privateKey = "1bcb0ae8c17945acfaf9ea546c0b754a599fddf27425bac7e532590324137a7d"; // the private key of the L1 which is sending the transaction
const account = "Bob"; // the receiving L2 account in NFT deposit
const asset_contract = "0xD0b6eee86DFAE935E837EcC187A63D3882eDA022"; // the l1 contract address of NFT
const token_id = 4; // the ID of NFT in L1 contract

const res = await sdk.depositNft(privateKey, account, asset_contract, token_id);

console.log("tx hash: ", res);

Example Result

tx hash: 0x832b75753c073b29a11431386f2faa744ced1c95603e8ea30e4aa5fd7ca3d14d

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

Example

  1. Deposit BEP20 assets like REY and LEG (advance approval required for assets)

import { SDK } from "@zecrey/zecrey-legend-js-sdk";

const sdk = new SDK();
await sdk.initial();

const privateKey = "1bcb0ae8c17945acfaf9ea546c0b754a599fddf27425bac7e532590324137a7d"; // the private key of the L1 which is sending the transaction
const account = "Bob"; // the L2 account that LEG is deposited to
const amount = "100000000000000"; // 0.0001 LEG
const asset_contract = "0x364Ed72f329f1BD56AE84b941D1c6E4E260cE152"; // the contract address of LEG

const res = await sdk.deposit(privateKey, account, amount, asset_contract);

console.log("tx hash: ", res);
  1. Deposit BNB

import { SDK } from "@zecrey/zecrey-legend-js-sdk";

const sdk = new SDK();
await sdk.initial();

const privateKey = "1bcb0ae8c17945acfaf9ea546c0b754a599fddf27425bac7e532590324137a7d"; // the private key of the L1 which is sending the transaction
const account = "Bob"; // the L2 account that LEG is deposited to
const amount = "100000000000000"; // 0.0001 BNB 

const res = await sdk.deposit(privateKey, account, amount);

console.log("tx hash: ", res);

Example Result

tx hash: 0xca0f43ae1e7d3ff868170fee2d0a1254772294aca43f2cf221aa602bd3cd5db3

DepositNft
Deposit