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
  • User Registration
  • Register Account With Private Key

Was this helpful?

  1. Go & JS SDK Basic Guides

4. Register Users

User Registration

The Zecrey account is represented by a public key, which is generated with the L1 private key.User registration consists of two parts:

  1. Generating Zecrey L2 user account for the L1 account

  2. Registering the L1 to L2 correspondence

This enables the following functionality:

  • A user with an L1 account now has an associated L2 account on Zecrey.

  • L1 users can deposit L1 assets into their L2 accounts.

  • L2 users can perform transactions on Zecrey (create orders, trade assets, transfer assets, etc.).

  • L2 users can withdraw their L2 assets to their L1 accounts.

On-chain registration

  1. First, register a user on the contract related to Zecrey L1.

  2. Then Zecrey L2 synchronizes with the L1 registration of the user. All transactions executed by the user on L2 will be recorded under this registered L1/L2 user.

What happens during the user registration process?

  • Register an account in the L1 contract and match the unique name of the tagged account to this account.

  • Link the account to L2 by submitting the associated information.

  • The L2 program recognizes the associated information submitted by the user, confirms it, saves it in the database, and the registration of the account is complete.

This is an overview of the user registration process:

Register Account With Private Key

  • Since sending a transaction to L1 will consume a certain amount of gas fee, to ensure successful registration, the user needs to ensure that he or she has BNB in the address.

  1. RegisterAccountWithPrivateKey will submit a registration transaction to L1 for registration, and this function will internally determine whether the account has been registered. If it has been registered, will directly return to the client.

  2. If the RegisterAccountWithPrivateKey function determines internally that the user has not registered on L1, the first step will be executed with the L1 private key, accountName and other information input by the user.

📚SDK REFERENCE

Example

  • Register an account with the name "Alice"

    • Prepare accountName, L1Addr and privateKey.

    • Register an account on L1.

    • If you have not registered before, wait for about 30 seconds and then check whether the registration is successful.

      Note: it takes some time for L1 to confirm the transaction and L2 to synchronize the transaction with L1.

package main

import (
   "encoding/json"
   "fmt"
   "time"

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

func main() {
   accountName := "Alice"
   l1Addr := "0xD207262DEA01aE806fA2dCaEdd489Bd2f5FABcFE"                             //the address of l1 account
   privateKey := "0x1a061a8e74cee1ce2e2ddd29f5afea99ecfbaf1998b6d349a8c09a368e637b8e" //the private key of l1
   client, err := sdk.RegisterAccountWithPrivateKey(accountName, l1Addr, privateKey)
   if err != nil {
      panic(err)
   }
   isRegister, err := sdk.IfAccountRegistered(accountName)
   if err != nil {
      panic(err)
   }


   if !isRegister{
      time.Sleep(time.Second * 30) //wait for l1 to verify the transaction
      isRegister, err = sdk.IfAccountRegistered(accountName)
      if err != nil {
         panic(err)
      }
      
      data, _ := json.Marshal(isRegister)
      fmt.Println("GetAccountIsRegistered:", string(data))

      accountName, l2pk, seed := client.GetMyInfo() //get information about your account through GetMyInfo()
      fmt.Println("accountName:", accountName)      //account name
      fmt.Println("l2pk:", l2pk)                    //l2 publick key
      fmt.Println("seed:", seed)                    //l2 private key
   }

}

Example result

GetAccountIsRegistered:true
accountName:Alice
l2pk:22fc6f5d74c8639245462a0af6b5c931bd209c04034b28421a60336635ab85950a3163e68ec29319ca200fac009408369b0a1f75200a118aded920cd240e1358
seed:0x7ea589236ac7e6034a40ad31f27a6ea1bbaeb7746ba5e8d3408a3abb480a8688

Example

  • Register an account with the name "Alice"

    • Prepare accountName, L1Addr and privateKey.

    • Register an account on L1.

    • If you have not registered before, wait for about 30 seconds and then check whether the registration is successful.

      Note: it takes some time for L1 to confirm the transaction and L2 to synchronize the transaction with L1.

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

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

const account_name = "Alice.zec";
const address = "0xD207262DEA01aE806fA2dCaEdd489Bd2f5FABcFE";
const privateKey = "0x1a061a8e74cee1ce2e2ddd29f5afea99ecfbaf1998b6d349a8c09a368e637b8e";

const res = await sdk.registerAccountWithPrivateKey(account_name, address, privateKey);

console.log(res);

Example result

{
    accountName:"Alice.zec",
    l2pk:22fc6f5d74c8639245462a0af6b5c931bd209c04034b28421a60336635ab85950a3163e68ec29319ca200fac009408369b0a1f75200a118aded920cd240e1358
}
Previous3. SDK SignatureNext5. Mint Assets

Last updated 2 years ago

Was this helpful?

Note: can determine if the account has been registered.

IfAccountRegistered
RegisterAccountWithPrivateKey