The private key of the account.
OptionalproviderL2: Web3ZKsyncL2The provider instance for connecting to a L2 network.
OptionalproviderL1: Web3ZKsyncL1The provider instance for connecting to a L1 network.
import { Web3ZKsyncL1, Web3ZKsyncL2, ZKsyncWallet } from "web3-plugin-zksync";
const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
const l2Provider = new Web3ZKsyncL2("https://sepolia.era.zksync.dev");
const l1Provider = new Web3ZKsyncL1("https://rpc.sepolia.org");
const wallet = new ZKsyncWallet(PRIVATE_KEY, l2Provider, l1Provider);
import { Web3 } from "web3";
import { ZkSyncPlugin } from "web3-plugin-zksync";
const web3 = new Web3("https://rpc.sepolia.org");
web3.registerPlugin(new ZkSyncPlugin("https://sepolia.era.zksync.dev"));
const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
const zkWallet = new web3.ZKsync.ZkWallet(PRIVATE_KEY);
Protected_contextReturns a context (provider + Signer) instance for connecting to a L1 network.
Protected_contextReturns a provider instance for connecting to an L2 network.
Bridging ERC20 tokens from L1 requires approving the tokens to the ZKsync Era smart contract.
The L1 address of the token.
The amount of the token to be approved.
Optionaloverrides: TransactionOverrides & { bridgeAddress?: string }Transaction's overrides which may be used to pass L1 gasLimit, gasPrice, value, etc.
A promise that resolves to the response of the approval transaction.
Withdraws funds from the initiated deposit, which failed when finalizing on L2.
If the deposit L2 transaction has failed, it sends an L1 transaction calling claimFailedDeposit method of the
L1 bridge, which results in returning L1 tokens back to the depositor.
The L2 transaction hash of the failed deposit.
Optionaloverrides: TransactionOverridesTransaction's overrides which may be used to pass L1 gasLimit, gasPrice, value, etc.
A promise that resolves to the response of the claimFailedDeposit transaction.
Transfers the specified token from the associated account on the L1 network to the target account on the L2 network.
The token can be either ETH or any ERC20 token. For ERC20 tokens, enough approved tokens must be associated with
the specified L1 bridge (default one or the one defined in transaction.bridgeAddress).
In this case, depending on is the chain ETH-based or not transaction.approveERC20 or transaction.approveBaseERC20
can be enabled to perform token approval. If there are already enough approved tokens for the L1 bridge,
token approval will be skipped. To check the amount of approved tokens for a specific bridge,
use the getAllowanceL1 method.
The transaction object containing deposit details.
Estimates the amount of gas required for a deposit transaction on the L1 network. Gas for approving ERC20 tokens is not included in the estimation.
In order for estimation to work, enough token allowance is required in the following cases:
The transaction details.
Estimates the amount of gas required for a request execute transaction.
The transaction details.
Proves the inclusion of the L2->L1 withdrawal message.
Hash of the L2 transaction where the withdrawal was initiated.
Optionalindex: number = 0In case there were multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize.
Optionaloverrides: TransactionOverridesTransaction's overrides which may be used to pass L1 gasLimit, gasPrice, value, etc.
A promise that resolves to the proof of inclusion of the withdrawal message.
Returns the parameters required for finalizing a withdrawal from the withdrawal transaction's log on the L1 network.
Hash of the L2 transaction where the withdrawal was initiated.
Optionalindex: number = 0In case there were multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize.
Returns the amount of approved tokens for a specific L1 bridge.
The Ethereum address of the token.
OptionalbridgeAddress: stringThe address of the bridge contract to be used.
Defaults to the default ZKsync Era bridge, either L1EthBridge or L1Erc20Bridge.
OptionalblockTag: BlockNumberOrTagThe block in which an allowance should be checked. Defaults to 'committed', i.e., the latest processed block.
Returns the amount of the token held by the account on the L1 network.
Optionaltoken: stringThe address of the token. Defaults to ETH if not provided.
OptionalblockTag: BlockNumberOrTagThe block in which the balance should be checked. Defaults to 'committed', i.e., the latest processed block.
Returns the base cost for an L2 transaction.
The parameters for calculating the base cost.
Returns Contract wrapper of the Bridgehub smart contract.
Returns the parameters for the approval token transaction based on the deposit token and amount. Some deposit transactions require multiple approvals. Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified amount.
The address of the token to deposit.
The amount of the token to deposit.
Returns a populated deposit transaction.
The transaction details.
Retrieves the full needed ETH fee for the deposit. Returns the L1 fee and the L2 fee FullDepositFee.
The transaction details.
Returns L1 bridge contracts.
There is no separate Ether bridge contract, Bridgehub is used instead.
Returns Contract wrapper of the ZKsync Era smart contract.
Returns the transaction confirmation data that is part of L2->L1 message.
The hash of the L2 transaction where the message was initiated.
Optionalindex: number = 0In case there were multiple transactions in one message, you may pass an index of the transaction which confirmation data should be fetched.
Returns the parameters for the approval token transaction based on the request execute transaction. Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified transaction.
The request execute transaction on which approval parameters are calculated.
Returns a populated request execute transaction.
The transaction details.
Returns whether the withdrawal transaction is finalized on the L1 network.
Hash of the L2 transaction where the withdrawal was initiated.
Optionalindex: number = 0In case there were multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize.
Designed for users who prefer a simplified approach by providing only the necessary data to create a valid transaction.
The only required fields are transaction.to and either transaction.data or transaction.value (or both, if the method is payable).
Any other fields that are not set will be prepared by this method.
The transaction request that needs to be populated.
import { Transaction, utils, Web3 } from "web3";
import { types, ZkSyncPlugin, ZKsyncWallet } from "web3-plugin-zksync";
async function main() {
const web3: Web3 = new Web3("https://rpc.sepolia.org");
web3.registerPlugin(new ZkSyncPlugin("https://sepolia.era.zksync.dev"));
const zksync: ZkSyncPlugin = web3.zkSync;
const PRIVATE_KEY: string = "<WALLET_PRIVATE_KEY>";
const wallet: ZKsyncWallet = new zksync.ZkWallet(PRIVATE_KEY);
const EIP712_TX_TYPE = 0x71;
const TO_ADDRESS = "<TO_ADDRESS>";
const populatedTx: types.Eip712TxData | Transaction = await wallet.populateTransaction({
type: utils.toHex(EIP712_TX_TYPE),
to: TO_ADDRESS,
value: utils.toHex(7_000_000_000),
});
}
Requests execution of an L2 transaction from L1.
The transaction details.
A promise that resolves to the response of the execution request.
Optional_context: Web3ZKsyncL1 | Web3ZKsyncL2Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on L1 network.
Withdrawal transaction request.
StaticcreateOptionalprovider: Web3ZKsyncL2OptionalproviderL1: Web3ZKsyncL1
Capabilities for integrating, creating, and managing ZKsync wallets.