Last updated
Last updated
In the following article, we will use this wallet as example:
The only transaction that made on Layer-1 is deposit. It has two sub-types which are DepositETH
and DepositERC20
.
Example Code:
Example code:
When submitting transaction to ZKSwap, the API requires 3 fields: tx
, signature
and fastProcessing
.In the following docs, Signed Transaction
refers to the tx
field and ETH Signature
refers to the signature
field.
After getting private key, you will need to register you publick key hash to ZKSwap so that it can verify transations that you sent.
Before submit transaction to ZKSwap, you need to sign the the transaction data.
After the account has been "registered" on ZKSwap (via transfer or deposit), you can change the account's pubKeyHash
in order to make any transaction on Layer-2. This is a special transaction that you don't need to sign it with Layer-2's private key.
Transaction Fields
Signed Transaction Example
ETH Signature
NOTE: The {pubKeyHash}
in the above message doesn't contain 0x as prefix. The {hexlifiedNonce}
and {hexlifiedAccountId}
has 4-bytes length with 0 padding in the start and 0x as prefx. See example for reference.
Transaction Fields
Full Bytes Example
Signed Transaction Example
ETH Signature
Transaction Fields
Full Bytes Example
Signed Transaction Example
ETH Signature
Let's take swap token A for token B as example. There are two cases:
If A is a fee token, the fee token of swap is A. The number of fee is calculated by amountIn * 5 / 9995
If A is not a fee token, the fee token of swap is B. The number of fee is amountOut * 5 /10000
. It's not amountOutMin
. amountOut
equals amountOutMin
then slipplage is 0.
Transaction Fields
Full Bytes Example
Signed Transaction Example
ETH Signature
Transaction Fields
Full Bytes Example
Signed Transaction Example
ETH Signature
Transaction Fields
Full Bytes Example
Signed Transaction Example
ETH Signature
Like other projects, you must approve ZKSwap's main contract address to spend your ERC20 tokens in order to deposit. Be careful for those tokens that has limit on changing allowance (See ).
Sign the following message with Layer-1's private key to get Layer-2's seed. And use to get private key.
Here's a full example of getting private key using in JavaScript.