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.

    Note: IfAccountRegistered can determine if the account has been registered.

  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.


  • 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 (


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 {
   isRegister, err := sdk.IfAccountRegistered(accountName)
   if err != nil {

   if !isRegister{
      time.Sleep(time.Second * 30) //wait for l1 to verify the transaction
      isRegister, err = sdk.IfAccountRegistered(accountName)
      if err != nil {
      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


Last updated