Skip to content

Commit

Permalink
feat(js): add l1TokenAddress wallet and signer
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion committed Oct 11, 2024
1 parent 0b51305 commit 55245ed
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
36 changes: 36 additions & 0 deletions content/10.js/00.ethers/05.api/10.v5/20.accounts/01.wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,42 @@ const WITHDRAWAL_HASH = "<WITHDRAWAL_TX_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<string>
```

#### Example

```ts
import { Wallet, Provider, utils } from "zksync-ethers";
import { ethers } from "ethers";

const PRIVATE_KEY = "<WALLET_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.
Expand Down
33 changes: 33 additions & 0 deletions content/10.js/00.ethers/05.api/10.v5/20.accounts/03.l1signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,39 @@ const WITHDRAWAL_HASH = "<WITHDRAWAL_TX_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<string>
```

#### 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.
Expand Down

0 comments on commit 55245ed

Please sign in to comment.