zkLink Docs
Search
K

Layer1 Transaction

There are two categories of zkLink transactions: L1Transaction and L2Transaction.
L1 Transactions are initiated by calling Layer1 contracts.
L2Transactions are initiated by calling zkLink API sendTransaction, check Layer2 Transaction for details.

Deposit

Deposit from Layer 1 to zkLink Layer 2.

Payload

Field
Description
type
Deposit
fromChainId
The chain id defined by zkLink, the chain that the deposit is initiated on
from
The initiator of the deposit
to
The recipient of the deposit. An account will be created if it does not exist on zkLink Layer 2
subAccountId
The subaccount id of the recipient
l1SourceToken
The token deducted from the initiator on Layer 1
l2TargetToken
The token received by the recipient on zkLink Layer 2
amount
The amount of deposit
serialId
The serial number of the event, used as nonce
ethHash
The transaction that generated this event on Layer 1

Example

{
"type": "Deposit",
"fromChainId": 1,
"from": "0x76920dfacad4f28f97d6209977c1057b9e3e5cad",
"subAccountId": 1,
"l1SourceToken": 18,
"l2TargetToken": 1,
"amount": "4000000000000000000000",
"to": "0x76920dfacad4f28f97d6209977c1057b9e3e5cad",
"serialId": 53,
"ethHash": "0xaaa1e7a5bc48e7cfaa562a4d1a5abc1d6dc5e7f7683e89eb00e895d438f0acab"
}

FullExit

Payload

Field
Description
type
FullExit
toChainId
The chain id defined by zkLink, to which the user wish to withdrawal
accountId
The id of the withdrawal account
subAccountId
The id of the subaccount for withdrawal
exitAddress
The Layer1 address of the recipient
l2SourceToken
The token deducted from the withdrawal account on Layer 2
l1TargetToken
The token received by the recipient on Layer 1
serialId
The serial number of the event, used as nonce
ethHash
The transaction that generated this event on Layer 1

Example

{
"type": "FullExit",
"toChainId": 1,
"accountId": 25,
"subAccountId": 1,
"exitAddress": "0xae08c2e27765faef5cb05908dbac12242caf91af",
"l2SourceToken": 47,
"l1TargetToken": 47,
"serialId": 43,
"ethHash": "0x748d32538f71d937d9e2c47adc26c499d0451b87e4fd337c2d6190c3271dafd7"
}
Parse the BalanceUpdate generated by FullExit (the state changes caused by execution of the transaction will be returned in getBlockByNumber and getTransactionByHash) to get the amount of FullExit withdrawal. For example, the state changes generated by the above transaction are as follows:
[
{
"type": "BalanceUpdate",
"updateId": 19,
"accountId": 25,
"subAccountId": 1,
"coinId": 47,
"oldBalance": "1120000000000000000",
"newBalance": "0",
"oldNonce": 0,
"newNonce": 0
}
]
The formula to calculate the withdrawal amount is:
var fullExitAmount = update.oldBalance - update.newBalance;
version: 4457a91