Skip to main content

L2

Modules exposes Lido MultiChain deployments. See full info here.

LidoSDKL2

This is core module for all L2 functionality. It will throw error if used on with chains that are not currently supported.

ChainwsETHstETH+(un)Wrap
Optimism Sepolia
Optmism
🔜

Use this helper to understand which contracts are supported on chain:

import {
LidoSDKL2,
LIDO_L2_CONTRACT_NAMES,
CHAINS,
} from '@lidofinance/lido-ethereum-sdk';

LidoSDKL2.isContractAvailableOn(
LIDO_L2_CONTRACT_NAMES.wsteth,
CHAINS.OptimismSepolia,
); // true
// Example
LidoSDKL2.isContractAvailableOn(LIDO_L2_CONTRACT_NAMES.steth, CHAINS.Arbitrum); // false

Fields

Methods

On L2 with stETH deployments bridged wstETH is wrapped to stETH. And stETH is unwrapped to wstETH. Those semantics are upkept in SDK with more explicit naming. See LIP-22 for more details.

Wrap bridged wstETH to stETH

To wrap stETH you first need to approve stETH to wrap contract:

import { LidoSDK } from '@lidofinance/lido-ethereum-sdk';

const lidoSDK = new LidoSDK({
rpcUrls: ['https://rpc-url'],
chainId: 11155420, // OP sepolia
web3Provider: LidoSDKCore.createWeb3Provider(11155420, window.ethereum),
});

// get existing allowance
const allowance = await lidoSDK.l2.getWstethForWrapAllowance();

// if value is more than allowance perform approve
if (allowance < value) {
const approveResult = await lidoSDK.wrap.approveWstethForWrap({
value,
callback,
});
}

// wrap wstETH
const wrapTx = await lidoSDK.wrap.wrapWstethToSteth({ value, callback });

const { stethReceived, wstethWrapped } = wrapTx.results;

Unwrap stETH to wstETH

// unwrap stETH to receive wstETH
const unwrapTx = await lidoSDK.l2.unwrapStethToWsteth({
value: unwrapAmount,
callback,
});

console.log(unwrapTx.result.stethUnwrapped, unwrapTx.result.wstethReceived);

Wrap utilities

For all transaction methods helper methods are available similar to stake module:

  • ...populateTX: returns ready to sign transaction object with all data encoded
  • ...simulateTX: performs dry-ran of the transaction to see if it will execute on the network

LidoSDKL2Wsteth

This submodule is built on top of existing ERC20 modules and has extra functionality. See docs for all ERC20 related methods. For original L2 ABI functionality use .getL2Contract() and get raw Viem contract instance.

LidoSDKL2Steth

This submodule is built on top of existing ERC20 modules but has extra L2 stETH related features. See docs for all ERC20 related methods. For original L2 ABI functionality use .getL2Contract() and get raw Viem contract instance.

import { LidoSDK } from '@lidofinance/lido-ethereum-sdk';

const lidoSDK = new LidoSDK({
rpcUrls: ['https://rpc-url'],
chainId: 11155420, // OP sepolia
web3Provider: LidoSDKCore.createWeb3Provider(11155420, window.ethereum),
});

// balance of stETH for account in shares
const balanceShares = await lidoSDK.l2.steth.balanceShares(address);

// transferring shares is equivalent to transferring corresponding amount of stETH
const transferTx = await lidoSDK.l2.steth.transferShares({
account,
amount,
to,
});

// converting stETH amount to shares trough on-chain call based on actual share rate
// This also can be used to convert stETH to wstETH as 1 wstETH = 1 share
const shares = await lidoSDK.l2.steth.convertToShares(1000n);
// reverse
const steth = await lidoSDK.l2.steth.convertToSteth(1000n);

// total supply of shares and ether in protocol
const totalShares = await lidoSDK.totalShares();