diff --git a/content/10.js/00.ethers/05.api/10.v5/20.accounts/01.wallet.md b/content/10.js/00.ethers/05.api/10.v5/20.accounts/01.wallet.md index d0aa95a..aa96c70 100644 --- a/content/10.js/00.ethers/05.api/10.v5/20.accounts/01.wallet.md +++ b/content/10.js/00.ethers/05.api/10.v5/20.accounts/01.wallet.md @@ -1464,6 +1464,42 @@ const WITHDRAWAL_HASH = ""; const isFinalized = await wallet.isWithdrawalFinalized(WITHDRAWAL_HASH); ``` +### `l1TokenAddress` + +Returns the L1 token address equivalent for a L2 token address as they are not equal. +ETH address is set to zero address. + +::callout{icon="i-heroicons-exclamation-triangle" color="amber"} +Only works for tokens bridged on default ZKsync Era bridges. +:: + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------- |---------------------------------| +| `token` | `Address` | The address of the token on L2. | + +```ts +async l1TokenAddress(token: Address): Promise +``` + +#### Example + +```ts +import { Wallet, Provider, utils } from "zksync-ethers"; +import { ethers } from "ethers"; + +const PRIVATE_KEY = ""; + +const provider = Provider.getDefaultProvider(types.Network.Sepolia); +const ethProvider = ethers.getDefaultProvider("sepolia"); +const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + +const tokenL2 = "0xe1134444211593Cfda9fc9eCc7B43208615556E2"; + +console.log(`Token L1 address: ${await wallet.l1TokenAddress(tokenL1)}`); +``` + ### `l2TokenAddress` Returns the L2 token address equivalent for a L1 token address as they are not equal. ETH's address is set to zero address. diff --git a/content/10.js/00.ethers/05.api/10.v5/20.accounts/03.l1signer.md b/content/10.js/00.ethers/05.api/10.v5/20.accounts/03.l1signer.md index 4cf5f8d..8bc883d 100644 --- a/content/10.js/00.ethers/05.api/10.v5/20.accounts/03.l1signer.md +++ b/content/10.js/00.ethers/05.api/10.v5/20.accounts/03.l1signer.md @@ -1007,6 +1007,39 @@ const WITHDRAWAL_HASH = ""; const isFinalized = await signer.isWithdrawalFinalized(WITHDRAWAL_HASH); ``` +### `l1TokenAddress` + +Returns the L1 token address equivalent for a L2 token address as they are not equal. +ETH address is set to zero address. + +::callout{icon="i-heroicons-exclamation-triangle" color="amber"} +Only works for tokens bridged on default ZKsync Era bridges. +:: + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------- |---------------------------------| +| `token` | `Address` | The address of the token on L2. | + +```ts +async l1TokenAddress(token: Address): Promise +``` + +#### Example + +```ts +import { Provider, L1Signer, types } from "zksync-ethers"; +import { ethers } from "ethers"; + +const browserProvider = new ethers.providers.Web3Provider(window.ethereum); +const signer = L1Signer.from(browserProvider.getSigner(), Provider.getDefaultProvider(types.Network.Sepolia)); + +const tokenL2 = "0xe1134444211593Cfda9fc9eCc7B43208615556E2"; + +console.log(`Token L1 address: ${await wallet.l1TokenAddress(tokenL1)}`); +``` + ### `l2TokenAddress` Returns the L2 token address equivalent for a L1 token address as they are not equal. ETH's address is set to zero address.