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:
Generating Zecrey L2 user account for the L1 account
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
First, register a user on the contract related to Zecrey L1.
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.
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.
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
andprivateKey
.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.
Example result
Last updated