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
  • Create transfer

Was this helpful?

  1. Go & JS SDK Basic Guides

9. Asset Transfers

Previous8. Asset DepositsNext10. Asset Withdrawals

Last updated 2 years ago

Was this helpful?

For various reasons, users may wish to transfer their assets from one wallet to another, for example, to send assets as gifts.

Initialize SDK

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

Create transfer

  • All NFT transactions will be confirmed by Zecrey. Zecrey will ensure that it is submitted to L1 once the transaction is confirmed.

    • 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

      ✅

      toAccountName

      The receiver's account name

      ✅

📚SDK REFERENCE

Example

  • TransferNft allows users to change the owner of NFT. However, the creator of the NFT will never change. Each time an NFT is transferred, the creator will receive a royalty, which is calculated by the NFT's TreasuryRate set by its creator.

  • Alice transfers to Bob the NFT with NftId = 6

    1. Initialize the client

    2. Transfer the NFT to Bob

package main

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


func main() {
    var NftId int64 = 6
    accountName := "Alice"
    seed := "0x6a1a320d14790f2d9aa9a37769f4833d583a3f7f974fd452a3990aeb0e7a6052"
    toAccountName := "Bob"
    
    c, err := sdk.NewClient(accountName, seed) 	 
    if err != nil { panic(err) }
    
    result, err := c.TransferNft(NftId, toAccountName)
    if err != nil { panic(err) }
    
    data, _ := json.Marshal(result)
    fmt.Println("TransferNft:", string(data))
}

Example result

TransferNft: {"success":true}

Example

  • TransferNft allows users to change the owner of NFT. However, the creator of the NFT will never change. Each time an NFT is transferred, the creator will receive a royalty, which is calculated by the NFT's TreasuryRate set by its creator.

  • Alice transfers to Bob the NFT with NftId = 6

    1. Initialize the client

    2. Transfer the NFT to Bob

With the private key:

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

const account_name = "Alice.zec";
const seed = "ee823a72698fd05c70fbdf36ba2ea467d33cf628c94ef030383efcb39581e43f";

const client = new Client(account_name, seed);
await client.initialize();

const nft_id = 6;
const to_account_name = "Bob.zec";
const res = await client.transferNft(nft_id, to_account_name);

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 = 6;
const to_account_name = "Bob.zec";
const res = await sdk.transferNft(account_name, account_index, nft_id, to_account_name);

console.log("success", res);

Example result

success: true

TransferNft