zksync-ethers
Version:
A Web3 library for interacting with the ZkSync Layer 2 scaling solution.
987 lines (986 loc) • 155 kB
TypeScript
import { ethers, BigNumberish, BytesLike, BlockTag, Filter, FilterByBlockHash, TransactionRequest as EthersTransactionRequest, JsonRpcTransactionRequest, Networkish, Eip1193Provider, JsonRpcError, JsonRpcResult, JsonRpcPayload } from 'ethers';
import { IL2AssetRouter, IL2Bridge, IL2NativeTokenVault, IL2SharedBridge } from './typechain';
import { Address, TransactionResponse, TransactionRequest, TransactionStatus, PriorityOpResponse, BalancesMap, TransactionReceipt, Block, Log, TransactionDetails, BlockDetails, ContractAccountInfo, Network as ZkSyncNetwork, BatchDetails, Fee, RawBlockTransaction, PaymasterParams, StorageProof, LogProof, Token, ProtocolVersion, FeeParams, TransactionWithDetailedOutput } from './types';
import { Signer } from './signer';
type Constructor<T = {}> = new (...args: any[]) => T;
export declare function JsonRpcApiProvider<TBase extends Constructor<ethers.JsonRpcApiProvider>>(ProviderType: TBase): {
new (...args: any[]): {
/**
* Sends a JSON-RPC `_payload` (or a batch) to the underlying channel.
*
* @param _payload The JSON-RPC payload or batch of payloads to send.
* @returns A promise that resolves to the result of the JSON-RPC request(s).
*/
_send(_payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult | JsonRpcError>>;
/**
* Returns the addresses of the main contract and default ZKsync Era bridge contracts on both L1 and L2.
*/
contractAddresses(): {
bridgehubContract?: Address;
mainContract?: Address;
erc20BridgeL1?: Address;
erc20BridgeL2?: Address;
wethBridgeL1?: Address;
wethBridgeL2?: Address;
sharedBridgeL1?: Address;
sharedBridgeL2?: Address;
baseToken?: Address;
l1Nullifier?: Address;
l1NativeTokenVault?: Address;
};
_getBlockTag(blockTag?: BlockTag): string | Promise<string>;
_wrapLog(value: any): Log;
_wrapBlock(value: any): Block;
_wrapTransactionResponse(value: any): TransactionResponse;
_wrapTransactionReceipt(value: any): TransactionReceipt;
/**
* Resolves to the transaction receipt for `txHash`, if mined.
* If the transaction has not been mined, is unknown or on pruning nodes which discard old transactions
* this resolves to `null`.
*
* @param txHash The hash of the transaction.
*/
getTransactionReceipt(txHash: string): Promise<TransactionReceipt | null>;
/**
* Resolves to the transaction for `txHash`.
* If the transaction is unknown or on pruning nodes which discard old transactions this resolves to `null`.
*
* @param txHash The hash of the transaction.
*/
getTransaction(txHash: string): Promise<TransactionResponse>;
/**
* Resolves to the block corresponding to the provided `blockHashOrBlockTag`.
* If `includeTxs` is set to `true` and the backend supports including transactions with block requests,
* all transactions will be included in the returned block object, eliminating the need for remote calls
* to fetch transactions separately.
*
* @param blockHashOrBlockTag The hash or tag of the block to retrieve.
* @param [includeTxs] A flag indicating whether to include transactions in the block.
*/
getBlock(blockHashOrBlockTag: BlockTag, includeTxs?: boolean): Promise<Block>;
/**
* Resolves to the list of Logs that match `filter`.
*
* @param filter The filter criteria to apply.
*/
getLogs(filter: Filter | FilterByBlockHash): Promise<Log[]>;
/**
* Returns the account balance for the specified account `address`, `blockTag`, and `tokenAddress`.
* If `blockTag` and `tokenAddress` are not provided, the balance for the latest committed block and ETH token
* is returned by default.
*
* @param address The account address for which the balance is retrieved.
* @param [blockTag] The block tag for getting the balance on. Latest committed block is the default.
* @param [tokenAddress] The token address. ETH is the default token.
*/
getBalance(address: Address, blockTag?: BlockTag, tokenAddress?: Address): Promise<bigint>;
/**
* Returns the L2 token address equivalent for a L1 token address as they are not equal.
* ETH address is set to zero address.
*
* @remarks Only works for tokens bridged on default ZKsync Era bridges.
*
* @param token The address of the token on L1.
* @param bridgeAddress The address of custom bridge, which will be used to get l2 token address.
*/
l2TokenAddress(token: Address, bridgeAddress?: Address): Promise<string>;
/**
* Returns the L1 token address equivalent for a L2 token address as they are not equal.
* ETH address is set to zero address.
*
* @remarks Only works for tokens bridged on default ZKsync Era bridges.
*
* @param token The address of the token on L2.
*/
l1TokenAddress(token: Address): Promise<string>;
/**
* Return the protocol version.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_getprotocolversion zks_getProtocolVersion} JSON-RPC method.
*
* @param [id] Specific version ID.
*/
getProtocolVersion(id?: number): Promise<ProtocolVersion>;
/**
* Returns an estimate of the amount of gas required to submit a transaction from L1 to L2 as a bigint object.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-estimategasl1tol2 zks_estimateL1ToL2} JSON-RPC method.
*
* @param transaction The transaction request.
*/
estimateGasL1(transaction: TransactionRequest): Promise<bigint>;
/**
* Returns an estimated {@link Fee} for requested transaction.
*
* @param transaction The transaction request.
*/
estimateFee(transaction: TransactionRequest): Promise<Fee>;
/**
* Returns the current fee parameters.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_getFeeParams zks_getFeeParams} JSON-RPC method.
*/
getFeeParams(): Promise<FeeParams>;
/**
* Returns an estimate (best guess) of the gas price to use in a transaction.
*/
getGasPrice(): Promise<bigint>;
/**
* Returns the proof for a transaction's L2 to L1 log sent via the `L1Messenger` system contract.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getl2tol1logproof zks_getL2ToL1LogProof} JSON-RPC method.
*
* @param txHash The hash of the L2 transaction the L2 to L1 log was produced within.
* @param [index] The index of the L2 to L1 log in the transaction.
*/
getLogProof(txHash: BytesLike, index?: number): Promise<LogProof | null>;
/**
* Returns the range of blocks contained within a batch given by batch number.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getl1batchblockrange zks_getL1BatchBlockRange} JSON-RPC method.
*
* @param l1BatchNumber The L1 batch number.
*/
getL1BatchBlockRange(l1BatchNumber: number): Promise<[number, number] | null>;
/**
* Returns the Bridgehub smart contract address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getbridgehubcontract zks_getBridgehubContract} JSON-RPC method.
*/
getBridgehubContractAddress(): Promise<Address>;
/**
* Returns the main ZKsync Era smart contract address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getmaincontract zks_getMainContract} JSON-RPC method.
*/
getMainContractAddress(): Promise<Address>;
/**
* Returns the L1 base token address.
*/
getBaseTokenContractAddress(): Promise<Address>;
/**
* Returns whether the chain is ETH-based.
*/
isEthBasedChain(): Promise<boolean>;
/**
* Returns whether the `token` is the base token.
*/
isBaseToken(token: Address): Promise<boolean>;
/**
* Returns the testnet {@link https://docs.zksync.io/build/developer-reference/account-abstraction.html#paymasters paymaster address}
* if available, or `null`.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-gettestnetpaymaster zks_getTestnetPaymaster} JSON-RPC method.
*/
getTestnetPaymasterAddress(): Promise<Address | null>;
/**
* Returns the addresses of the default ZKsync Era bridge contracts on both L1 and L2.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getbridgecontracts zks_getBridgeContracts} JSON-RPC method.
*/
getDefaultBridgeAddresses(): Promise<{
erc20L1: string;
erc20L2: string;
wethL1: string;
wethL2: string;
sharedL1: string;
sharedL2: string;
}>;
_setL1NullifierAndNativeTokenVault(l1Nullifier: Address, l1NativeTokenVault: Address): void;
/**
* Returns contract wrapper. If given address is shared bridge address it returns Il2SharedBridge and if its legacy it returns Il2Bridge.
**
* @param address The bridge address.
*
* @example
*
* import { Provider, types, utils } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const l2Bridge = await provider.connectL2Bridge("<L2_BRIDGE_ADDRESS>");
*/
connectL2Bridge(address: Address): Promise<IL2SharedBridge | IL2Bridge>;
connectL2NativeTokenVault(): Promise<IL2NativeTokenVault>;
connectL2AssetRouter(): Promise<IL2AssetRouter>;
/**
* Returns true if passed bridge address is legacy and false if its shared bridge.
**
* @param address The bridge address.
*
* @example
*
* import { Provider, types, utils } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const isBridgeLegacy = await provider.isL2BridgeLegacy("<L2_BRIDGE_ADDRESS>");
* console.log(isBridgeLegacy);
*/
isL2BridgeLegacy(address: Address): Promise<boolean>;
/**
* Returns all balances for confirmed tokens given by an account address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getallaccountbalances zks_getAllAccountBalances} JSON-RPC method.
*
* @param address The account address.
*/
getAllAccountBalances(address: Address): Promise<BalancesMap>;
/**
* Returns confirmed tokens. Confirmed token is any token bridged to ZKsync Era via the official bridge.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_getconfirmedtokens zks_getConfirmedTokens} JSON-RPC method.
*
* @param start The token id from which to start.
* @param limit The maximum number of tokens to list.
*/
getConfirmedTokens(start?: number, limit?: number): Promise<Token[]>;
/**
* @deprecated In favor of {@link getL1ChainId}
*
* Returns the L1 chain ID.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-l1chainid zks_L1ChainId} JSON-RPC method.
*/
l1ChainId(): Promise<number>;
/**
* Returns the L1 chain ID.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-l1chainid zks_L1ChainId} JSON-RPC method.
*/
getL1ChainId(): Promise<number>;
/**
* Returns the latest L1 batch number.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-l1batchnumber zks_L1BatchNumber} JSON-RPC method.
*/
getL1BatchNumber(): Promise<number>;
/**
* Returns data pertaining to a given batch.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getl1batchdetails zks_getL1BatchDetails} JSON-RPC method.
*
* @param number The L1 batch number.
*/
getL1BatchDetails(number: number): Promise<BatchDetails>;
/**
* Returns additional zkSync-specific information about the L2 block.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getblockdetails zks_getBlockDetails} JSON-RPC method.
*
* @param number The block number.
*/
getBlockDetails(number: number): Promise<BlockDetails>;
/**
* Returns data from a specific transaction given by the transaction hash.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-gettransactiondetails zks_getTransactionDetails} JSON-RPC method.
*
* @param txHash The transaction hash.
*/
getTransactionDetails(txHash: BytesLike): Promise<TransactionDetails>;
/**
* Returns bytecode of a contract given by its hash.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getbytecodebyhash zks_getBytecodeByHash} JSON-RPC method.
*
* @param bytecodeHash The bytecode hash.
*/
getBytecodeByHash(bytecodeHash: BytesLike): Promise<Uint8Array>;
/**
* Returns data of transactions in a block.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getrawblocktransactions zks_getRawBlockTransactions} JSON-RPC method.
*
* @param number The block number.
*/
getRawBlockTransactions(number: number): Promise<RawBlockTransaction[]>;
/**
* Returns Merkle proofs for one or more storage values at the specified account along with a Merkle proof
* of their authenticity.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getproof zks_getProof} JSON-RPC method.
*
* @param address The account to fetch storage values and proofs for.
* @param keys The vector of storage keys in the account.
* @param l1BatchNumber The number of the L1 batch specifying the point in time at which the requested values are returned.
*/
getProof(address: Address, keys: string[], l1BatchNumber: number): Promise<StorageProof>;
/**
* Executes a transaction and returns its hash, storage logs, and events that would have been generated if the
* transaction had already been included in the block. The API has a similar behaviour to `eth_sendRawTransaction`
* but with some extra data returned from it.
*
* With this API Consumer apps can apply "optimistic" events in their applications instantly without having to
* wait for ZKsync block confirmation time.
*
* It’s expected that the optimistic logs of two uncommitted transactions that modify the same state will not
* have causal relationships between each other.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_sendRawTransactionWithDetailedOutput zks_sendRawTransactionWithDetailedOutput} JSON-RPC method.
*
* @param signedTx The signed transaction that needs to be broadcasted.
*/
sendRawTransactionWithDetailedOutput(signedTx: string): Promise<TransactionWithDetailedOutput>;
/**
* Returns the populated withdrawal transaction.
*
* @param transaction The transaction details.
* @param transaction.amount The amount of token.
* @param transaction.token The token address.
* @param [transaction.from] The sender's address.
* @param [transaction.to] The recipient's address.
* @param [transaction.bridgeAddress] The bridge address.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction overrides including `gasLimit`, `gasPrice`, and `value`.
*/
getWithdrawTx(transaction: {
amount: BigNumberish;
token?: Address;
from?: Address;
to?: Address;
bridgeAddress?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.Overrides;
}): Promise<EthersTransactionRequest>;
/**
* Returns the gas estimation for a withdrawal transaction.
*
* @param transaction The transaction details.
* @param transaction.token The token address.
* @param transaction.amount The amount of token.
* @param [transaction.from] The sender's address.
* @param [transaction.to] The recipient's address.
* @param [transaction.bridgeAddress] The bridge address.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction overrides including `gasLimit`, `gasPrice`, and `value`.
*/
estimateGasWithdraw(transaction: {
token: Address;
amount: BigNumberish;
from?: Address;
to?: Address;
bridgeAddress?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.Overrides;
}): Promise<bigint>;
/**
* Returns the populated transfer transaction.
*
* @param transaction Transfer transaction request.
* @param transaction.to The address of the recipient.
* @param transaction.amount The amount of the token to transfer.
* @param [transaction.token] The address of the token. Defaults to ETH.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction's overrides which may be used to pass L2 `gasLimit`, `gasPrice`, `value`, etc.
*/
getTransferTx(transaction: {
to: Address;
amount: BigNumberish;
from?: Address;
token?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.Overrides;
}): Promise<EthersTransactionRequest>;
/**
* Returns the gas estimation for a transfer transaction.
*
* @param transaction Transfer transaction request.
* @param transaction.to The address of the recipient.
* @param transaction.amount The amount of the token to transfer.
* @param [transaction.token] The address of the token. Defaults to ETH.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction's overrides which may be used to pass L2 `gasLimit`, `gasPrice`, `value`, etc.
*/
estimateGasTransfer(transaction: {
to: Address;
amount: BigNumberish;
from?: Address;
token?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.Overrides;
}): Promise<bigint>;
/**
* Returns a new filter by calling {@link https://ethereum.github.io/execution-apis/api-documentation/ eth_newFilter}
* and passing a filter object.
*
* @param filter The filter query to apply.
*/
newFilter(filter: FilterByBlockHash | Filter): Promise<bigint>;
/**
* Returns a new block filter by calling {@link https://ethereum.github.io/execution-apis/api-documentation/ eth_newBlockFilter}.
*/
newBlockFilter(): Promise<bigint>;
/**
* Returns a new pending transaction filter by calling {@link https://ethereum.github.io/execution-apis/api-documentation/ eth_newPendingTransactionFilter}.
*/
newPendingTransactionsFilter(): Promise<bigint>;
/**
* Returns an array of logs by calling {@link https://ethereum.github.io/execution-apis/api-documentation/ eth_getFilterChanges}.
*
* @param idx The filter index.
*/
getFilterChanges(idx: bigint): Promise<Array<Log | string>>;
/**
* Returns the status of a specified transaction.
*
* @param txHash The hash of the transaction.
*/
getTransactionStatus(txHash: string): Promise<TransactionStatus>;
/**
* Broadcasts the `signedTx` to the network, adding it to the memory pool of any node for which the transaction
* meets the rebroadcast requirements.
*
* @param signedTx The signed transaction that needs to be broadcasted.
* @returns A promise that resolves with the transaction response.
*/
broadcastTransaction(signedTx: string): Promise<TransactionResponse>;
/**
* Returns a L2 transaction response from L1 transaction response.
*
* @param l1TxResponse The L1 transaction response.
*/
getL2TransactionFromPriorityOp(l1TxResponse: ethers.TransactionResponse): Promise<TransactionResponse>;
/**
* Returns a {@link PriorityOpResponse} from L1 transaction response.
*
* @param l1TxResponse The L1 transaction response.
*/
getPriorityOpResponse(l1TxResponse: ethers.TransactionResponse): Promise<PriorityOpResponse>;
_getPriorityOpConfirmationL2ToL1Log(txHash: string, index?: number): Promise<{
l2ToL1LogIndex: number;
l2ToL1Log: import("./types").L2ToL1Log;
l1BatchTxId: number | null;
}>;
/**
* Returns the transaction confirmation data that is part of `L2->L1` message.
*
* @param txHash The hash of the L2 transaction where the message was initiated.
* @param [index=0] In case there were multiple transactions in one message, you may pass an index of the
* transaction which confirmation data should be fetched.
* @throws {Error} If log proof can not be found.
*/
getPriorityOpConfirmation(txHash: string, index?: number): Promise<{
l1BatchNumber: number;
l2MessageIndex: number;
l2TxNumberInBlock: number | null;
proof: string[];
}>;
/**
* Returns the version of the supported account abstraction and nonce ordering from a given contract address.
*
* @param address The contract address.
*/
getContractAccountInfo(address: Address): Promise<ContractAccountInfo>;
/**
* Returns an estimation of the L2 gas required for token bridging via the default ERC20 bridge.
*
* @param providerL1 The Ethers provider for the L1 network.
* @param token The address of the token to be bridged.
* @param amount The deposit amount.
* @param to The recipient address on the L2 network.
* @param from The sender address on the L1 network.
* @param gasPerPubdataByte The current gas per byte of pubdata.
*/
estimateDefaultBridgeDepositL2Gas(providerL1: ethers.Provider, token: Address, amount: BigNumberish, to: Address, from?: Address, gasPerPubdataByte?: BigNumberish): Promise<bigint>;
/**
* Returns an estimation of the L2 gas required for token bridging via the custom ERC20 bridge.
*
* @param l1BridgeAddress The address of the custom L1 bridge.
* @param l2BridgeAddress The address of the custom L2 bridge.
* @param token The address of the token to be bridged.
* @param amount The deposit amount.
* @param to The recipient address on the L2 network.
* @param bridgeData Additional bridge data.
* @param from The sender address on the L1 network.
* @param gasPerPubdataByte The current gas per byte of pubdata.
* @param l2Value The `msg.value` of L2 transaction.
*/
estimateCustomBridgeDepositL2Gas(l1BridgeAddress: Address, l2BridgeAddress: Address, token: Address, amount: BigNumberish, to: Address, bridgeData: BytesLike, from: Address, gasPerPubdataByte?: BigNumberish, l2Value?: BigNumberish): Promise<bigint>;
/**
* Returns gas estimation for an L1 to L2 execute operation.
*
* @param transaction The transaction details.
* @param transaction.contractAddress The address of the contract.
* @param transaction.calldata The transaction call data.
* @param [transaction.caller] The caller's address.
* @param [transaction.l2Value] The deposit amount.
* @param [transaction.factoryDeps] An array of bytes containing contract bytecode.
* @param [transaction.gasPerPubdataByte] The current gas per byte value.
* @param [transaction.overrides] Transaction overrides including `gasLimit`, `gasPrice`, and `value`.
*/
estimateL1ToL2Execute(transaction: {
contractAddress: Address;
calldata: string;
caller?: Address;
l2Value?: BigNumberish;
factoryDeps?: ethers.BytesLike[];
gasPerPubdataByte?: BigNumberish;
overrides?: ethers.Overrides;
}): Promise<bigint>;
/**
* Returns `tx` as a normalized JSON-RPC transaction request, which has all values `hexlified` and any numeric
* values converted to Quantity values.
* @param tx The transaction request that should be normalized.
*/
getRpcTransaction(tx: TransactionRequest): JsonRpcTransactionRequest;
"__#17@#private": any;
_getOption<K extends keyof ethers.JsonRpcApiProviderOptions>(key: K): ethers.JsonRpcApiProviderOptions[K];
readonly _network: ethers.Network;
_perform(req: ethers.PerformActionRequest): Promise<any>;
_detectNetwork(): Promise<ethers.Network>;
_start(): void;
_waitUntilReady(): Promise<void>;
_getSubscriber(sub: ethers.Subscription): ethers.Subscriber;
readonly ready: boolean;
getRpcRequest(req: ethers.PerformActionRequest): {
method: string;
args: any[];
} | null;
getRpcError(payload: ethers.JsonRpcPayload, _error: ethers.JsonRpcError): Error;
send(method: string, params: any[] | Record<string, any>): Promise<any>;
getSigner(address?: string | number | undefined): Promise<ethers.JsonRpcSigner>;
listAccounts(): Promise<ethers.JsonRpcSigner[]>;
destroy(): void;
"__#14@#private": any;
readonly pollingInterval: number;
readonly provider: any;
readonly plugins: ethers.AbstractProviderPlugin[];
attachPlugin(plugin: ethers.AbstractProviderPlugin): any;
getPlugin<T extends ethers.AbstractProviderPlugin = ethers.AbstractProviderPlugin>(name: string): T | null;
disableCcipRead: boolean;
ccipReadFetch(tx: ethers.PerformActionTransaction, calldata: string, urls: string[]): Promise<string | null>;
getBlockNumber(): Promise<number>;
_getAddress(address: ethers.AddressLike): string | Promise<string>;
_getFilter(filter: ethers.Filter | ethers.FilterByBlockHash): ethers.PerformActionFilter | Promise<ethers.PerformActionFilter>;
_getTransactionRequest(_request: ethers.TransactionRequest): ethers.PerformActionTransaction | Promise<ethers.PerformActionTransaction>;
getNetwork(): Promise<ethers.Network>;
getFeeData(): Promise<ethers.FeeData>;
estimateGas(_tx: ethers.TransactionRequest): Promise<bigint>;
call(_tx: ethers.TransactionRequest): Promise<string>;
getTransactionCount(address: ethers.AddressLike, blockTag?: ethers.BlockTag | undefined): Promise<number>;
getCode(address: ethers.AddressLike, blockTag?: ethers.BlockTag | undefined): Promise<string>;
getStorage(address: ethers.AddressLike, _position: ethers.BigNumberish, blockTag?: ethers.BlockTag | undefined): Promise<string>;
getTransactionResult(hash: string): Promise<string | null>;
_getProvider(chainId: number): ethers.AbstractProvider;
getResolver(name: string): Promise<ethers.EnsResolver | null>; /**
* Returns the main ZKsync Era smart contract address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getmaincontract zks_getMainContract} JSON-RPC method.
*/
getAvatar(name: string): Promise<string | null>;
resolveName(name: string): Promise<string | null>;
lookupAddress(address: string): Promise<string | null>;
waitForTransaction(hash: string, _confirms?: number | null | undefined, timeout?: number | null | undefined): Promise<ethers.TransactionReceipt | null>;
waitForBlock(blockTag?: ethers.BlockTag | undefined): Promise<ethers.Block>;
_clearTimeout(timerId: number): void;
_setTimeout(_func: () => void, timeout?: number | undefined): number;
_forEachSubscriber(func: (s: ethers.Subscriber) => void): void;
_recoverSubscriber(oldSub: ethers.Subscriber, newSub: ethers.Subscriber): void;
on(event: ethers.ProviderEvent, listener: ethers.Listener): Promise<any>;
once(event: ethers.ProviderEvent, listener: ethers.Listener): Promise<any>;
emit(event: ethers.ProviderEvent, ...args: any[]): Promise<boolean>;
listenerCount(event?: ethers.ProviderEvent | undefined): Promise<number>;
listeners(event?: ethers.ProviderEvent | undefined): Promise<ethers.Listener[]>;
off(event: ethers.ProviderEvent, listener?: ethers.Listener | undefined): Promise<any>;
removeAllListeners(event?: ethers.ProviderEvent | undefined): Promise<any>;
addListener(event: ethers.ProviderEvent, listener: ethers.Listener): Promise<any>;
removeListener(event: ethers.ProviderEvent, listener: ethers.Listener): Promise<any>;
readonly destroyed: boolean;
paused: boolean;
pause(dropWhilePaused?: boolean | undefined): void;
resume(): void;
};
} & TBase;
declare const Provider_base: {
new (...args: any[]): {
/**
* Sends a JSON-RPC `_payload` (or a batch) to the underlying channel.
*
* @param _payload The JSON-RPC payload or batch of payloads to send.
* @returns A promise that resolves to the result of the JSON-RPC request(s).
*/
_send(_payload: ethers.JsonRpcPayload | ethers.JsonRpcPayload[]): Promise<(ethers.JsonRpcResult | ethers.JsonRpcError)[]>;
/**
* Returns the addresses of the main contract and default ZKsync Era bridge contracts on both L1 and L2.
*/
contractAddresses(): {
bridgehubContract?: string | undefined;
mainContract?: string | undefined;
erc20BridgeL1?: string | undefined;
erc20BridgeL2?: string | undefined;
wethBridgeL1?: string | undefined;
wethBridgeL2?: string | undefined;
sharedBridgeL1?: string | undefined;
sharedBridgeL2?: string | undefined;
baseToken?: string | undefined;
l1Nullifier?: string | undefined;
l1NativeTokenVault?: string | undefined;
};
_getBlockTag(blockTag?: ethers.BlockTag | undefined): string | Promise<string>;
_wrapLog(value: any): Log;
_wrapBlock(value: any): Block;
_wrapTransactionResponse(value: any): TransactionResponse;
_wrapTransactionReceipt(value: any): TransactionReceipt;
/**
* Resolves to the transaction receipt for `txHash`, if mined.
* If the transaction has not been mined, is unknown or on pruning nodes which discard old transactions
* this resolves to `null`.
*
* @param txHash The hash of the transaction.
*/
getTransactionReceipt(txHash: string): Promise<TransactionReceipt | null>;
/**
* Resolves to the transaction for `txHash`.
* If the transaction is unknown or on pruning nodes which discard old transactions this resolves to `null`.
*
* @param txHash The hash of the transaction.
*/
getTransaction(txHash: string): Promise<TransactionResponse>;
/**
* Resolves to the block corresponding to the provided `blockHashOrBlockTag`.
* If `includeTxs` is set to `true` and the backend supports including transactions with block requests,
* all transactions will be included in the returned block object, eliminating the need for remote calls
* to fetch transactions separately.
*
* @param blockHashOrBlockTag The hash or tag of the block to retrieve.
* @param [includeTxs] A flag indicating whether to include transactions in the block.
*/
getBlock(blockHashOrBlockTag: ethers.BlockTag, includeTxs?: boolean | undefined): Promise<Block>;
/**
* Resolves to the list of Logs that match `filter`.
*
* @param filter The filter criteria to apply.
*/
getLogs(filter: ethers.Filter | ethers.FilterByBlockHash): Promise<Log[]>;
/**
* Returns the account balance for the specified account `address`, `blockTag`, and `tokenAddress`.
* If `blockTag` and `tokenAddress` are not provided, the balance for the latest committed block and ETH token
* is returned by default.
*
* @param address The account address for which the balance is retrieved.
* @param [blockTag] The block tag for getting the balance on. Latest committed block is the default.
* @param [tokenAddress] The token address. ETH is the default token.
*/
getBalance(address: string, blockTag?: ethers.BlockTag | undefined, tokenAddress?: string | undefined): Promise<bigint>;
/**
* Returns the L2 token address equivalent for a L1 token address as they are not equal.
* ETH address is set to zero address.
*
* @remarks Only works for tokens bridged on default ZKsync Era bridges.
*
* @param token The address of the token on L1.
* @param bridgeAddress The address of custom bridge, which will be used to get l2 token address.
*/
l2TokenAddress(token: string, bridgeAddress?: string | undefined): Promise<string>;
/**
* Returns the L1 token address equivalent for a L2 token address as they are not equal.
* ETH address is set to zero address.
*
* @remarks Only works for tokens bridged on default ZKsync Era bridges.
*
* @param token The address of the token on L2.
*/
l1TokenAddress(token: string): Promise<string>;
/**
* Return the protocol version.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_getprotocolversion zks_getProtocolVersion} JSON-RPC method.
*
* @param [id] Specific version ID.
*/
getProtocolVersion(id?: number | undefined): Promise<ProtocolVersion>;
/**
* Returns an estimate of the amount of gas required to submit a transaction from L1 to L2 as a bigint object.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-estimategasl1tol2 zks_estimateL1ToL2} JSON-RPC method.
*
* @param transaction The transaction request.
*/
estimateGasL1(transaction: TransactionRequest): Promise<bigint>;
/**
* Returns an estimated {@link Fee} for requested transaction.
*
* @param transaction The transaction request.
*/
estimateFee(transaction: TransactionRequest): Promise<Fee>;
/**
* Returns the current fee parameters.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_getFeeParams zks_getFeeParams} JSON-RPC method.
*/
getFeeParams(): Promise<FeeParams>;
/**
* Returns an estimate (best guess) of the gas price to use in a transaction.
*/
getGasPrice(): Promise<bigint>;
/**
* Returns the proof for a transaction's L2 to L1 log sent via the `L1Messenger` system contract.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getl2tol1logproof zks_getL2ToL1LogProof} JSON-RPC method.
*
* @param txHash The hash of the L2 transaction the L2 to L1 log was produced within.
* @param [index] The index of the L2 to L1 log in the transaction.
*/
getLogProof(txHash: ethers.BytesLike, index?: number | undefined): Promise<LogProof | null>;
/**
* Returns the range of blocks contained within a batch given by batch number.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getl1batchblockrange zks_getL1BatchBlockRange} JSON-RPC method.
*
* @param l1BatchNumber The L1 batch number.
*/
getL1BatchBlockRange(l1BatchNumber: number): Promise<[number, number] | null>;
/**
* Returns the Bridgehub smart contract address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getbridgehubcontract zks_getBridgehubContract} JSON-RPC method.
*/
getBridgehubContractAddress(): Promise<string>;
/**
* Returns the main ZKsync Era smart contract address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getmaincontract zks_getMainContract} JSON-RPC method.
*/
getMainContractAddress(): Promise<string>;
/**
* Returns the L1 base token address.
*/
getBaseTokenContractAddress(): Promise<string>;
/**
* Returns whether the chain is ETH-based.
*/
isEthBasedChain(): Promise<boolean>;
/**
* Returns whether the `token` is the base token.
*/
isBaseToken(token: string): Promise<boolean>;
/**
* Returns the testnet {@link https://docs.zksync.io/build/developer-reference/account-abstraction.html#paymasters paymaster address}
* if available, or `null`.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-gettestnetpaymaster zks_getTestnetPaymaster} JSON-RPC method.
*/
getTestnetPaymasterAddress(): Promise<string | null>;
/**
* Returns the addresses of the default ZKsync Era bridge contracts on both L1 and L2.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getbridgecontracts zks_getBridgeContracts} JSON-RPC method.
*/
getDefaultBridgeAddresses(): Promise<{
erc20L1: string;
erc20L2: string;
wethL1: string;
wethL2: string;
sharedL1: string;
sharedL2: string;
}>;
_setL1NullifierAndNativeTokenVault(l1Nullifier: string, l1NativeTokenVault: string): void;
/**
* Returns contract wrapper. If given address is shared bridge address it returns Il2SharedBridge and if its legacy it returns Il2Bridge.
**
* @param address The bridge address.
*
* @example
*
* import { Provider, types, utils } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const l2Bridge = await provider.connectL2Bridge("<L2_BRIDGE_ADDRESS>");
*/
connectL2Bridge(address: string): Promise<IL2Bridge | IL2SharedBridge>;
connectL2NativeTokenVault(): Promise<IL2NativeTokenVault>;
connectL2AssetRouter(): Promise<IL2AssetRouter>;
/**
* Returns true if passed bridge address is legacy and false if its shared bridge.
**
* @param address The bridge address.
*
* @example
*
* import { Provider, types, utils } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const isBridgeLegacy = await provider.isL2BridgeLegacy("<L2_BRIDGE_ADDRESS>");
* console.log(isBridgeLegacy);
*/
isL2BridgeLegacy(address: string): Promise<boolean>;
/**
* Returns all balances for confirmed tokens given by an account address.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getallaccountbalances zks_getAllAccountBalances} JSON-RPC method.
*
* @param address The account address.
*/
getAllAccountBalances(address: string): Promise<BalancesMap>;
/**
* Returns confirmed tokens. Confirmed token is any token bridged to ZKsync Era via the official bridge.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_getconfirmedtokens zks_getConfirmedTokens} JSON-RPC method.
*
* @param start The token id from which to start.
* @param limit The maximum number of tokens to list.
*/
getConfirmedTokens(start?: number, limit?: number): Promise<Token[]>;
/**
* @deprecated In favor of {@link getL1ChainId}
*
* Returns the L1 chain ID.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-l1chainid zks_L1ChainId} JSON-RPC method.
*/
l1ChainId(): Promise<number>;
/**
* Returns the L1 chain ID.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-l1chainid zks_L1ChainId} JSON-RPC method.
*/
getL1ChainId(): Promise<number>;
/**
* Returns the latest L1 batch number.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-l1batchnumber zks_L1BatchNumber} JSON-RPC method.
*/
getL1BatchNumber(): Promise<number>;
/**
* Returns data pertaining to a given batch.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getl1batchdetails zks_getL1BatchDetails} JSON-RPC method.
*
* @param number The L1 batch number.
*/
getL1BatchDetails(number: number): Promise<BatchDetails>;
/**
* Returns additional zkSync-specific information about the L2 block.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getblockdetails zks_getBlockDetails} JSON-RPC method.
*
* @param number The block number.
*/
getBlockDetails(number: number): Promise<BlockDetails>;
/**
* Returns data from a specific transaction given by the transaction hash.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-gettransactiondetails zks_getTransactionDetails} JSON-RPC method.
*
* @param txHash The transaction hash.
*/
getTransactionDetails(txHash: ethers.BytesLike): Promise<TransactionDetails>;
/**
* Returns bytecode of a contract given by its hash.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getbytecodebyhash zks_getBytecodeByHash} JSON-RPC method.
*
* @param bytecodeHash The bytecode hash.
*/
getBytecodeByHash(bytecodeHash: ethers.BytesLike): Promise<Uint8Array>;
/**
* Returns data of transactions in a block.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getrawblocktransactions zks_getRawBlockTransactions} JSON-RPC method.
*
* @param number The block number.
*/
getRawBlockTransactions(number: number): Promise<RawBlockTransaction[]>;
/**
* Returns Merkle proofs for one or more storage values at the specified account along with a Merkle proof
* of their authenticity.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks-getproof zks_getProof} JSON-RPC method.
*
* @param address The account to fetch storage values and proofs for.
* @param keys The vector of storage keys in the account.
* @param l1BatchNumber The number of the L1 batch specifying the point in time at which the requested values are returned.
*/
getProof(address: string, keys: string[], l1BatchNumber: number): Promise<StorageProof>;
/**
* Executes a transaction and returns its hash, storage logs, and events that would have been generated if the
* transaction had already been included in the block. The API has a similar behaviour to `eth_sendRawTransaction`
* but with some extra data returned from it.
*
* With this API Consumer apps can apply "optimistic" events in their applications instantly without having to
* wait for ZKsync block confirmation time.
*
* It’s expected that the optimistic logs of two uncommitted transactions that modify the same state will not
* have causal relationships between each other.
*
* Calls the {@link https://docs.zksync.io/build/api.html#zks_sendRawTransactionWithDetailedOutput zks_sendRawTransactionWithDetailedOutput} JSON-RPC method.
*
* @param signedTx The signed transaction that needs to be broadcasted.
*/
sendRawTransactionWithDetailedOutput(signedTx: string): Promise<TransactionWithDetailedOutput>;
/**
* Returns the populated withdrawal transaction.
*
* @param transaction The transaction details.
* @param transaction.amount The amount of token.
* @param transaction.token The token address.
* @param [transaction.from] The sender's address.
* @param [transaction.to] The recipient's address.
* @param [transaction.bridgeAddress] The bridge address.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction overrides including `gasLimit`, `gasPrice`, and `value`.
*/
getWithdrawTx(transaction: {
amount: ethers.BigNumberish;
token?: string | undefined;
from?: string | undefined;
to?: string | undefined;
bridgeAddress?: string | undefined;
paymasterParams?: PaymasterParams | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<ethers.TransactionRequest>;
/**
* Returns the gas estimation for a withdrawal transaction.
*
* @param transaction The transaction details.
* @param transaction.token The token address.
* @param transaction.amount The amount of token.
* @param [transaction.from] The sender's address.
* @param [transaction.to] The recipient's address.
* @param [transaction.bridgeAddress] The bridge address.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction overrides including `gasLimit`, `gasPrice`, and `value`.
*/
estimateGasWithdraw(transaction: {
token: string;
amount: ethers.BigNumberish;
from?: string | undefined;
to?: string | undefined;
bridgeAddress?: string | undefined;
paymasterParams?: PaymasterParams | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<bigint>;
/**
* Returns the populated transfer transaction.
*
* @param transaction Transfer transaction request.
* @param transaction.to The address of the recipient.
* @param transaction.amount The amount of the token to transfer.
* @param [transaction.token] The address of the token. Defaults to ETH.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction's overrides which may be used to pass L2 `gasLimit`, `gasPrice`, `value`, etc.
*/
getTransferTx(transaction: {
to: string;
amount: ethers.BigNumberish;
from?: string | undefined;
token?: string | undefined;
paymasterParams?: PaymasterParams | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<ethers.TransactionRequest>;
/**
* Returns the gas estimation for a transfer transaction.
*
* @param transaction Transfer transaction request.
* @param transaction.to The address of the recipient.
* @param transaction.amount The amount of the token to transfer.
* @param [transaction.token] The address of the token. Defaults to ETH.
* @param [transaction.paymasterParams] Paymaster parameters.
* @param [transaction.overrides] Transaction's overrides which may be used to pass L2 `gasLimit`, `gasPrice`, `value`, etc.
*/
estimateGasTransfer(transaction: {
to: string;
amount: ethers.BigNumberish;
from?: string | undefined;
token?: string | undefined;
paymasterParams?: PaymasterParams | undefined;
overrides?: ethers.Overrides | undefined;