### Install Dependencies Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/examples/erlang-bridge/usage.md Navigate to the example directory and install Node.js dependencies. ```bash cd examples/erlang-bridge/src yarn install ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/installation.md Clone the lido-ethereum-sdk repository, navigate to the package directory, copy the environment example, and install dependencies using yarn. ```bash git clone https://github.com/lidofinance/lido-ethereum-sdk.git cd packages/lido-pulse cp .env.example .env yarn install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/README.md Starts a local development server for live preview. Changes are reflected without restarting. ```bash yarn start ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/examples/erlang-bridge/installation.md Navigate to the project directory and run this command to install all required Node.js dependencies. ```bash yarn install ``` -------------------------------- ### Install Lido Ethereum SDK Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/intro.md Install the Lido Ethereum SDK and its peer dependency viem using yarn. ```bash // SDK (stakes, wrap, withdrawals) yarn add viem @lidofinance/lido-ethereum-sdk ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/playground/README.md Copy the example environment file and fill in your local configuration details. ```bash fill .env.local as per .env.example ``` -------------------------------- ### Install Dependencies Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/README.md Run this command to install project dependencies using Yarn. ```bash yarn ``` -------------------------------- ### Start Erlang Shell Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/examples/erlang-bridge/usage.md Start the Erlang shell, ensuring the build artifacts are in the path. ```bash erl -pa _build/default/lib/*/ebin ``` -------------------------------- ### Install Lido Ethereum SDK Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/README.md Install the Lido Ethereum SDK using yarn. This package includes modules for staking, wrapping, and withdrawals. ```bash // SDK (stakes, wrap, withdrawals) yarn add @lidofinance/lido-ethereum-sdk ``` -------------------------------- ### Compile and Start Erlang Process Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/examples/erlang-bridge/README.md Commands to compile the Erlang code and start the Erlang shell with the necessary paths. ```bash rebar3 get-deps && rebar3 compile ``` ```bash erlc main.erl ``` ```bash erl -pa _build/default/lib/*/ebin ``` -------------------------------- ### Run Fastify Server in Development Mode Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/installation.md Use this command to start the Fastify server with hot reloading for development. ```bash yarn dev ``` -------------------------------- ### Start LidoPulse RPC Server Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/packages/lido-pulse/README.md Run the Fastify RPC server using the 'start' script. For development with hot reloading, use the 'dev' script. The server defaults to port 3000. ```bash yarn start ``` ```bash yarn dev ``` -------------------------------- ### Install Lido Ethereum SDK with npm Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/packages/sdk/README.md Use this command to add the Lido Ethereum SDK to your project if you are using npm as your package manager. ```bash npm install @lidofinance/lido-ethereum-sdk ``` -------------------------------- ### JSON-RPC Request with Typed Parameters Example Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/usage.md A complete JSON-RPC request example demonstrating the use of typed parameters, specifically a BigInt. ```json { "jsonrpc": "2.0", "method": "lidoSDK.someMethod", "params": { "param1": "value1", "bigNumberParam": { "__type": "bigInt", "value": "9007199254740991" } }, "id": 1 } ``` -------------------------------- ### Compile and Start Main Module in Erlang Shell Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/examples/erlang-bridge/README.md Compile the 'main' module within the Erlang shell and then start the Node.js process. ```erlang c(main). ``` ```erlang {ok, Port} = main:start(). ``` -------------------------------- ### Usage Examples Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/dual-governance.md Illustrates how to use the Dual Governance module in a TypeScript application. ```APIDOC ## Usage Examples ### Description Demonstrates practical usage of the Dual Governance module, including fetching veto signaling progress and checking governance warning status. ### Example 1: Get Veto Signaling Progress ```ts import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; const lidoSDK = new LidoSDK(); const dualGovernance = lidoSDK.dualGovernance; // Get the current veto signaling progress const progress = await dualGovernance.calculateCurrentVetoSignallingThresholdProgress(); console.log(`Current veto signaling support: ${progress.currentSupportPercent}%`); ``` ### Example 2: Check Governance Warning Status ```ts import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; const lidoSDK = new LidoSDK(); const dualGovernance = lidoSDK.dualGovernance; // Check if we should show a warning (e.g., if support is above 75%) const warningStatus = await dualGovernance.getGovernanceWarningStatus({ triggerPercent: 75 }); if (warningStatus.state === 'Warning') { console.log(`Warning: Veto support at ${warningStatus.currentVetoSupportPercent}%`); } else if (warningStatus.state === 'Blocked') { console.log('Governance is currently blocked (in VetoSignalling, VetoSignallingDeactivation, or RageQuit state)'); } ``` ``` -------------------------------- ### Install Lido Ethereum SDK with Yarn Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/packages/sdk/README.md Use this command to add the Lido Ethereum SDK to your project if you are using Yarn as your package manager. ```bash yarn add @lidofinance/lido-ethereum-sdk ``` -------------------------------- ### Initialize Lido SDK and Get Balances Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/w-steth.md Initializes the Lido SDK with public and wallet clients and demonstrates how to retrieve stETH and wstETH balances for a given address. Ensure you replace '' with your actual RPC endpoint. ```typescript import { createWalletClient, custom, hoodi, http, createPublicClient, } from 'viem'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); // Views const balanceStETH = await lidoSDK.steth.balance(address); const balanceWStETH = await lidoSDK.wsteth.balance(address); ``` -------------------------------- ### Wrap ETH to wstETH with Lido SDK Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/basic-examples.md Initializes the Lido SDK with wallet client for wrapping operations. Shows how to get wstETH contract details and perform an ETH wrap transaction. ```typescript import { createWalletClient, custom, hoodi, http, createPublicClient, } from 'viem'; const lidoSDK = new LidoSDK({ chainId: 17000, publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); // Contracts const addressWstETH = await lidoSDK.wrap.contractAddressWstETH(); const contractWstETH = await lidoSDK.withdraw.getContractWstETH(); // Calls const wrapTx = await lidoSDK.wrap.wrapEth({ value, account, }); const { stethWrapped, wstethReceived } = wrapTx.result; console.log(addressWstETH, 'wstETH contract address'); console.log(contractWstETH, 'wstETH contract'); console.log({ stethWrapped, wstethReceived }, 'wrap result'); ``` -------------------------------- ### Example Batch Response Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/batch-requests.md This snippet shows a batch JSON-RPC response corresponding to the example batch request. Note that the order of results may differ from the request order, emphasizing the importance of using the `id` field for correlation. ```json [ { "jsonrpc": "2.0", "result": [ { "amountOfStETH": "10000000000000000", "amountOfShares": "9995810557743733", "owner": "0x", "timestamp": "16973450812", "isFinalized": true, "isClaimed": false, "id": "777" } ], "id": 2 }, { "jsonrpc": "2.0", "result": "14066156191713469572", "id": 1 }, { "jsonrpc": "2.0", "result": { "eventName": "TokenRebased", "args": { "reportTimestamp": "1721072820", "timeElapsed": "4608", "preTotalShares": "1079179109989045486885777", "preTotalEther": "1093196098970760843229455", "postTotalShares": "1079179369664131812438396", "postTotalEther": "1093198738453702928397482", "sharesMintedAsFees": "260563376065765428" }, "address": "0x3f1c547b21f65e10480de3ad8e19faac46c95034", "topics": [ "0xff08c3ef606d198e316ef5b822193c489965899eb4e3c248cea1a4626c3eda50", "0x0000000000000000000000000000000000000000000000000000000066957cb4" ], "data": "0x000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000e4866ab1ef0fa0ba1b9100000000000000000000000000000000000000000000e77e477e6cbd9ce5f90f00000000000000000000000000000000000000000000e4866e4c7c2d1e2e317c00000000000000000000000000000000000000000000e77e6c1fc07dee9674aa000000000000000000000000000000000000000000000000039db5028fe06034", "blockNumber": "1934791", "transactionHash": "0x826b3e20a499dfb655828829ba08cab037b81873237397502159ea41f9186246", "transactionIndex": 16, "blockHash": "0x61ea6638b24ef3b0215556e67bb847e44f52c97e9f24b898452b3b6c426ee82e", "logIndex": 43, "removed": false }, "id": 3 } ] ``` -------------------------------- ### Initialize Lido SDK and Get ETH Balance Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/basic-examples.md Initializes the Lido SDK with a chain ID and public client. Demonstrates how to retrieve the ETH balance for a given address. ```typescript import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; import { http, createPublicClient, hoodi } from 'viem'; const lidoSDK = new LidoSDK({ chainId: 17000, publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), }); // Views const balanceETH = await lidoSDK.core.balanceETH(address); console.log(balanceETH.toString(), 'ETH balance'); ``` -------------------------------- ### Start Node.js Process from Erlang Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/examples/erlang-bridge/usage.md Initiate the Node.js process from Erlang and obtain the communication port. ```erlang {ok, Port} = main:start(). ``` -------------------------------- ### Stake ETH with Lido SDK Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/basic-examples.md Initializes the Lido SDK with wallet client capabilities for staking. Shows how to get contract addresses and initiate an ETH stake transaction. ```typescript import { createWalletClient, custom, hoodi, createPublicClient } from 'viem'; const lidoSDK = new LidoSDK({ chainId: 17000, publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); // Contracts const addressStETH = await lidoSDK.stake.contractAddressStETH(); const contractStETH = await lidoSDK.stake.getContractStETH(); // Calls const stakeTx = await lidoSDK.stake.stakeEth({ value, callback, referralAddress, }); console.log(addressStETH, 'stETH contract address'); console.log(contractStETH, 'stETH contract'); console.log(stakeTx, 'stake tx result'); ``` -------------------------------- ### LidoSDK Basic Usage Example Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/intro.md Demonstrates initializing LidoSDK and performing a balance check and a stake transaction. The stake transaction returns the amount of stETH and shares received. ```typescript const lidoSDK = new LidoSDK({ chainId: 17000, publicClient, walletClient, // optional }); // Views const balanceETH = await lidoSDK.core.balanceETH(address); // Calls const stakeTx = await lidoSDK.stake.stakeEth({ value, callback, referralAddress, account, }); // relevant results are returned with transaction const { stethReceived, sharesReceived } = stakeTx.result; console.log(balanceETH.toString(), 'ETH balance'); ``` -------------------------------- ### LidoSDK Usage Example Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/README.md Demonstrates basic usage of the LidoSDK, including fetching ETH balance and performing a stake transaction. The results include the amount of stETH and shares received. ```javascript const lidoSDK = new LidoSDK({ chainId: 17000, publicClient, walletClient, // only for sending/preparing transactions }); // Views const balanceETH = await lidoSDK.core.balanceETH(address); // Calls const stakeTx = await lidoSDK.stake.stakeEth({ value, callback, referralAddress, account, }); // relevant results are returned with transaction const { stethReceived, sharesReceived } = stakeTx.result; console.log(balanceETH.toString(), 'ETH balance'); ``` -------------------------------- ### Example JSON-RPC Response Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/usage.md A typical JSON-RPC response from the Lido Ethereum SDK server, showing the result of a successful request. ```json { "jsonrpc": "2.0", "result": "0x3F1c547b21f65e10480dE3ad8E19fAAC46C95034", "id": 1 } ``` -------------------------------- ### Lido SDK Shares Module Example Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/shares.md Demonstrates various functionalities of the Lido SDK shares module, including balance retrieval, transfers, conversions, and batch operations. Replace '' and '' with actual addresses. ```typescript import { LidoSDK, LidoSDKCore } from '@lidofinance/lido-ethereum-sdk'; import { createWalletClient, custom, http, createPublicClient, hoodi, } from 'viem'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), chainId: 17000, walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); const account = ''; const to = ''; const sharesBalance = await lidoSDK.shares.balance(account); const transferTx = await lidoSDK.shares.transfer({ account, to, amount: 1_000_000_000_000_000_000n, }); const sharesValue = await lidoSDK.shares.convertToShares(1_000n); const stethValue = await lidoSDK.shares.convertToSteth(1_000n); const shareRateValues = await lidoSDK.shares.getTotalSupply(); const stethBatch = await lidoSDK.shares.convertBatchSharesToSteth( [100n, '200', { amount: 1_000_000_000_000_000_000n, roundUp: true }], shareRateValues, ); const sharesBatch = await lidoSDK.shares.convertBatchStethToShares( [100n, 200n, 300n], shareRateValues, ); const pooledEthRoundUp = await lidoSDK.shares.getPooledEthBySharesRoundUp( 1000n, shareRateValues, ); ``` -------------------------------- ### Example Batch JSON-RPC Request Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/batch-requests.md This snippet demonstrates a batch JSON-RPC request containing three independent calls: shares balance, NFTs by account, and the last rebase event. Each call has a unique `id` for response matching. ```json [ { "jsonrpc": "2.0", "method": "shares.balance", "params": ["0x2f0EA53F92252167d658963f334a91de0824e322"], "id": 1 }, { "jsonrpc": "2.0", "method": "unsteth.getNFTsByAccount", "params": ["0x2f0EA53F92252167d658963f334a91de0824e322"], "id": 2 }, { "jsonrpc": "2.0", "method": "events.stethEvents.getLastRebaseEvent", "params": [], "id": 3 } ] ``` -------------------------------- ### Stake ETH with Callback Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/stake.md Use this function to stake ETH. Provide a callback to monitor transaction stages like signing, receipt, confirmation, and completion or errors. Requires wallet client setup. ```typescript import { LidoSDK, LidoSDKCore, StakeStageCallback, TransactionCallbackStage, SDKError, } from '@lidofinance/lido-ethereum-sdk'; import { createWalletClient, custom, hoodi, http, createPublicClient, } from 'viem'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), walletClient: createWalletClient({ transport: custom(window.ethereum), }), }); const callback: StakeStageCallback = ({ stage, payload }) => { switch (stage) { case TransactionCallbackStage.SIGN: console.log('wait for sign'); break; case TransactionCallbackStage.RECEIPT: console.log('wait for receipt'); console.log(payload, 'transaction hash'); break; case TransactionCallbackStage.CONFIRMATION: console.log('wait for confirmation'); console.log(payload, 'transaction receipt'); break; case TransactionCallbackStage.DONE: console.log('done'); console.log(payload, 'transaction confirmations'); break; case TransactionCallbackStage.ERROR: console.log('error'); console.log(payload, 'error object with code and message'); break; default: } }; try { const stakeTx = await lidoSDK.stake.stakeEth({ value, callback, referralAddress, account, }); console.log( stakeTx, 'transaction hash, transaction receipt, confirmations, stake result', stakeTx.result.stethReceived, stakeTx.result.sharesReceived, ); } catch (error) { console.log((error as SDKError).errorMessage, (error as SDKError).code); } ``` -------------------------------- ### Send JSON-RPC Request using curl Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/usage.md Example of sending a JSON-RPC request to the Lido Ethereum SDK server using the curl command-line tool. It includes the endpoint, method, parameters, and request ID. ```bash curl -X POST http://localhost:3000/rpc \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "core.getContractAddress", "params": ["lido"], "id": 1 }' ``` -------------------------------- ### Form a JSON-RPC Request for Rewards Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/usage.md Example of a JSON-RPC request to get rewards from the chain. It specifies the method, parameters including a BigInt type, and a request ID. ```json { "jsonrpc": "2.0", "method": "rewards.getRewardsFromChain", "params": { "address": "0x2f0EA53F92252167d658963f334a91de0824e322", "stepBlock": 10000, "back": { "days": { "value": 1, "__type": "bigInt" } } }, "id": 1 } ``` -------------------------------- ### Initialize SDK with Viem PublicClient Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/usage.md Initialize the LidoSDK by passing your own Viem PublicClient instance. The walletClient is optional. ```typescript import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; import { createPublicClient, http } from 'viem'; import { hoodi } from 'viem/chains'; const publicClient = createPublicClient({ chain: hoodi, transport: http(''), }); const sdk = new LidoSDK({ publicClient, walletClient, }); ``` -------------------------------- ### Get Veto Signaling Progress and Warning Status Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/dual-governance.md This example demonstrates how to retrieve the current veto signaling support percentage and check if a governance warning should be displayed based on a trigger percentage. It also shows how to identify if the governance is blocked. ```typescript import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; const lidoSDK = new LidoSDK(); const dualGovernance = lidoSDK.dualGovernance; // Get the current veto signaling progress const progress = await dualGovernance.calculateCurrentVetoSignallingThresholdProgress(); console.log(`Current veto signaling support: ${progress.currentSupportPercent}%`); // Check if we should show a warning (e.g., if support is above 75%) const warningStatus = await dualGovernance.getGovernanceWarningStatus({ triggerPercent: 75 }); if (warningStatus.state === 'Warning') { console.log(`Warning: Veto support at ${warningStatus.currentVetoSupportPercent}%`); } else if (warningStatus.state === 'Blocked') { console.log('Governance is currently blocked (in VetoSignalling, VetoSignallingDeactivation, or RageQuit state)'); } ``` -------------------------------- ### Initialize SDK with Viem WalletClient Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/usage.md Initialize the LidoSDK with both Viem PublicClient and WalletClient for transaction signing. Ensure the wallet client is correctly configured. ```typescript import { LidoSDK, LidoSDKCore } from '@lidofinance/lido-ethereum-sdk'; import { createWalletClient, createPublicClient, custom, http, hoodi, } from 'viem'; const publicClient = createPublicClient({ chain: hoodi, transport: http(''), }); const walletClient = createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }); const sdk = new LidoSDK({ chainId: 17000, publicClient, walletClient, }); ``` -------------------------------- ### Build Packages Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/playground/README.md Run this command to build the SDK packages before proceeding. ```bash yarn build:packages ``` -------------------------------- ### Initialize Viem PublicClient Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/README.md Create a Viem PublicClient instance for interacting with the Ethereum network. Ensure you provide the correct chain and RPC URL. ```typescript // Pass your own viem PublicClient import { createPublicClient, http } from 'viem'; import { hoodi } from 'viem/chains'; const publicClient = createPublicClient({ chain: hoodi, // Replace `` with the url of your Ethereum RPC provider. transport: http(''), }); ``` -------------------------------- ### Initialize Lido SDK with Clients Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/shares.md Initializes the LidoSDK with Viem public and wallet clients. Ensure to replace '' with your actual RPC endpoint. ```typescript import { createWalletClient, custom, http, createPublicClient, hoodi, } from 'viem'; import { LidoSDK, LidoSDKCore } from '@lidofinance/lido-ethereum-sdk'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); const shares = lidoSDK.shares; ``` -------------------------------- ### Initialize Lido SDK and Interact with unstETH NFTs Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/unsteth-nft.md Initializes the Lido SDK with a Viem public client and demonstrates how to interact with the unstETH NFT contract. This includes fetching contract addresses, retrieving NFT details by account or token ID, and initiating NFT transfers. ```typescript import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; import { createPublicClient, hoodi, http } from 'viem'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), }); // Contracts const addressUnstETH = await lidoSDK.unsteth.contractAddress(); const contractUnstETH = await lidoSDK.unsteth.getContract(); // views const nfts = await lidoSDK.unsteth.getNFTsByAccount(account); const owner = await lidoSDK.unsteth.getAccountByNFT(tokenId); // Calls const transfer = await lidoSDK.unsteth.transfer({ id, to, from, // optional to call transferFrom account, callback, }); ``` -------------------------------- ### Get ERC20 Token Metadata Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/w-steth.md Retrieves metadata for ERC20 tokens, including name, symbol, decimals, and the ERC2612 Domain separator. Also shows how to get nonces, total supply, and the unhashed ERC2612 domain. ```typescript // Other helpful functions are exposed // - `erc20Metadata` returns token name, symbol, decimals and ERC2612 Domain separator. // - `nonces` returns current permit nonce for account // - `totalSupply` returns total supply of the token, for (w)stETH tokens this is a variable that changes over time // - `erc721Domain` return unhashed ERC2612 domain, used for signing permits ``` -------------------------------- ### Initialize Lido SDK and stVault Module Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/stvault.md Set up the LidoSDK instance with public and wallet clients. Access the stVault module for vault-related operations. ```typescript import { LidoSDK, LidoSDKCore } from '@lidofinance/lido-ethereum-sdk'; import { createWalletClient, custom, hoodi, http, createPublicClient, } from 'viem'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); const stVault = lidoSDK.stVaultModule; ``` -------------------------------- ### Get Withdrawal Requests Status Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Retrieves the status of all withdrawal requests for a given account. ```APIDOC ## GET /api/withdrawal/status ### Description Retrieves the status of all withdrawal requests for a given account. ### Method GET ### Endpoint /api/withdrawal/status ### Parameters #### Query Parameters - **account** (Address | Account) - Required - The account address. ### Response #### Success Response (200) - **Type**: Array of RequestStatusWithId objects - **Structure of each object**: - **id** (bigint) - The request identifier. - **isFinalized** (boolean) - A flag indicating whether the request has been finalized. - **isClaimed** (boolean) - A flag indicating whether the request has already been claimed. - **amountOfStETH** (bigint) - The amount of stETH to be withdrawn. - **amountOfShares** (bigint) - The amount of shares to be burned. - **owner** (Address) - The account address that initiated the request. - **timestamp** (bigint) - The timestamp of the request. - **stringId** (string) - The request identifier in string format. #### Response Example { "example": "[ { "id": 12345, "isFinalized": true, "isClaimed": false, "amountOfStETH": "1000000000000000000", "amountOfShares": "1000000000000000000", "owner": "0x123...", "timestamp": 1678886400, "stringId": "12345" } ]" } ``` -------------------------------- ### Initialize SDK with RPC URLs Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/usage.md Initialize the LidoSDK by providing RPC URLs. The SDK will create the Viem PublicClient internally. The chainId must be provided explicitly. ```typescript import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; // viem is still required as peer dependency for inner workings of SDK import { hoodi } from 'viem/chains'; const sdk = new LidoSDK({ // in this chainId must be provided explicitly chainId: hoodi.id, // multiple RPC URLs are supported and used in viem's fallback transport rpcUrls: [''], }); ``` -------------------------------- ### Get Pending Requests Info Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Retrieves information about pending withdrawal requests for a given account. ```APIDOC ## GET /api/withdrawal/pending/info ### Description Retrieves information about pending withdrawal requests for a given account. ### Method GET ### Endpoint /api/withdrawal/pending/info ### Parameters #### Query Parameters - **account** (Address | Account) - Required - The account address. ### Response #### Success Response (200) - **Type**: Object - **Structure**: - **pendingRequests** (Array[RequestStatusWithId]) - A list of requests pending finalization. - **pendingAmountStETH** (bigint) - The amount of ETH pending claiming. #### Response Example { "example": "{ "pendingRequests": [ { "id": 67890, "isFinalized": false, "isClaimed": false, "amountOfStETH": "500000000000000000", "amountOfShares": "500000000000000000", "owner": "0x456...", "timestamp": 1678886500, "stringId": "67890" } ], "pendingAmountStETH": "500000000000000000" }" } ``` -------------------------------- ### Get Claimable Requests Info Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Retrieves information about claimable withdrawal requests for a given account. ```APIDOC ## GET /api/withdrawal/claimable/info ### Description Retrieves information about claimable withdrawal requests for a given account. ### Method GET ### Endpoint /api/withdrawal/claimable/info ### Parameters #### Query Parameters - **account** (Address | Account) - Required - The account address. ### Response #### Success Response (200) - **Type**: Object - **Structure**: - **claimableRequests** (Array[RequestStatusWithId]) - A list of requests that can be claimed. - **claimableAmountStETH** (bigint) - The amount of ETH available for claiming. #### Response Example { "example": "{ "claimableRequests": [ { "id": 12345, "isFinalized": true, "isClaimed": false, "amountOfStETH": "1000000000000000000", "amountOfShares": "1000000000000000000", "owner": "0x123...", "timestamp": 1678886400, "stringId": "12345" } ], "claimableAmountStETH": "1000000000000000000" }" } ``` -------------------------------- ### Get Withdrawal Requests Info Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Retrieves detailed information about withdrawal requests for a given account. ```APIDOC ## POST /api/withdrawals/info/getWithdrawalRequestsInfo ### Description Retrieves information about withdrawal requests for a specific account. ### Method POST ### Endpoint /api/withdrawals/info/getWithdrawalRequestsInfo ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **account** (Address | Account) - Required - The account address for which to retrieve withdrawal request information. ### Request Example ```json { "account": "0x123..." } ``` ### Response #### Success Response (200) - **withdrawalRequestsInfo** (array) - An array of objects, each containing details about a withdrawal request. #### Response Example ```json { "withdrawalRequestsInfo": [ { "requestId": 1n, "amount": "1.5 ETH", "status": "pending" }, { "requestId": 2n, "amount": "2.0 ETH", "status": "completed" } ] } ``` ``` -------------------------------- ### Configure Public Client Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/examples/erlang-bridge/usage.md Create a public client instance for interacting with the Ethereum chain. Replace 'RPC_URL' with your actual RPC endpoint and set the desired chain. ```typescript const publicClient = createPublicClient({ chain: mainnet, transport: http('RPC_URL'), }); ``` -------------------------------- ### Deploy Website (SSH) Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/README.md Deploys the website using SSH. Assumes SSH is configured for deployment. ```bash USE_SSH=true yarn deploy ``` -------------------------------- ### Initialize LidoSDK Instance Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/intro.md Create an instance of LidoSDK by providing chainId, a viem PublicClient, and an optional walletClient. ```typescript // Pass your own viem PublicClient import { createPublicClient, http } from 'viem'; import { hoodi } from 'viem/chains'; const publicClient = createPublicClient({ chain: hoodi, transport: http(''), }); const sdk = new LidoSDK({ chainId: 17000, publicClient, walletClient, // optional }); ``` -------------------------------- ### JSON-RPC Request with Array Parameters Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/lidoPulse/get-started/usage.md Example of a JSON-RPC request where parameters are provided as an array, including a BigInt type. ```json { "jsonrpc": "2.0", "method": "core.anotherMethod", "params": ["value1", 42, { "__type": "bigInt", "value": "9007199254740991" }], "id": 2 } ``` -------------------------------- ### Get Withdrawal Waiting Time By Amount Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Estimates the waiting time for a withdrawal based on a specified amount of ETH. ```APIDOC ## GET /api/withdrawal/waiting-time/by-amount ### Description Estimates the waiting time for a withdrawal based on a specified amount of ETH. ### Method GET ### Endpoint /api/withdrawal/waiting-time/by-amount ### Parameters #### Query Parameters - **amount** (bigint) - Optional - The amount of withdrawable eth. If not provided, default queue information is used. ### Response #### Success Response (200) - **Type**: Object - **Structure**: - **requestInfo** (Object) - Information about withdrawal request - **finalizationIn** (number) - The time needed for withdrawal in milliseconds. - **finalizationAt** (string) - The time when request finalized for withdrawal. - **type** (WaitingTimeCalculationType) - Type of final source of eth for withdrawal. - **status** (WaitingTimeStatus) - Status of withdrawal request. - **nextCalculationAt** (string) - Time when next calculation can be changed. #### Response Example { "example": "{ "requestInfo": { "finalizationIn": 3600000, "finalizationAt": "2023-03-15T12:00:00Z", "type": "LATEST_WITHDRAWALS_QUEUE" }, "status": "CALCULATED", "nextCalculationAt": "2023-03-15T11:00:00Z" }" } ``` -------------------------------- ### Fetch Lido Rebase Events Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/lido-events.md Demonstrates how to initialize the Lido SDK and fetch various rebase events. Ensure you have the necessary RPC URL and chain configuration. ```typescript import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; import { http, createPublicClient, hoodi } from 'viem'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), }); const lastRebaseEvent = await lidoSDK.events.stethEvents.getLastRebaseEvent(); const firstRebaseEvent = await lidoSDK.events.stethEvents.getFirstRebaseEvent({ days: 3, }); const lastRebaseEventsByCount = await lidoSDK.events.stethEvents.getLastRebaseEvents({ count: 7 }); const lastRebaseEventsByDays = await lidoSDK.events.stethEvents.getRebaseEventsByDays({ days: 7 }); console.log(lastRebaseEvent, 'last rebase event'); console.log(firstRebaseEvent, 'first rebase event'); console.log(lastRebaseEventsByCount, 'last rebase events by count'); console.log(lastRebaseEventsByDays, 'last rebase events by days'); ``` -------------------------------- ### Get Withdrawal Waiting Time By Request IDs Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Estimates the waiting time for withdrawals based on a list of request IDs. ```APIDOC ## GET /api/withdrawal/waiting-time/by-request-ids ### Description Estimates the waiting time for withdrawals based on a list of request IDs. ### Method GET ### Endpoint /api/withdrawal/waiting-time/by-request-ids ### Parameters #### Query Parameters - **ids** (Array[bigint]) - Required - The ids of withdrawal requests. ### Response #### Success Response (200) - **Type**: Object - **Structure**: - **requestInfo** (Object) - Information about withdrawal request - **finalizationIn** (number) - The time needed for withdrawal in milliseconds. - **finalizationAt** (string) - The time when request finalized for withdrawal. - **type** (WaitingTimeCalculationType) - Type of final source of eth for withdrawal. - **status** (WaitingTimeStatus) - Status of withdrawal request. - **nextCalculationAt** (string) - Time when next calculation can be changed. #### Response Example { "example": "{ "requestInfo": { "finalizationIn": 7200000, "finalizationAt": "2023-03-15T14:00:00Z", "type": "LATEST_WITHDRAWALS_QUEUE" }, "status": "CALCULATED", "nextCalculationAt": "2023-03-15T13:00:00Z" }" } ``` -------------------------------- ### Shares Conversion Methods Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/shares.md Provides examples of using conversion methods to exchange between stETH and shares, including on-chain and off-chain calculations. ```APIDOC ## Shares Conversion Methods ### Description This section details the methods available for converting between stETH and shares, both on-chain and through off-chain calculations. It also covers batch conversion functionalities. ### Conversion Methods - `convertToShares(stethAmount)`: On-chain conversion from stETH amount to shares using `getSharesByPooledEth`. - `convertToSteth(sharesAmount)`: On-chain conversion from shares amount to stETH using `getPooledEthByShares`. - `convertBatchStethToShares(stethAmounts, shareRateValues?)`: Batch conversion of stETH amounts to shares. Optionally reuses a share-rate snapshot. - `convertBatchSharesToSteth(sharesAmounts, shareRateValues?)`: Batch conversion of shares amounts to stETH. Supports optional per-item rounding up. - `getSharesByPooledEth(stethAmount, shareRateValues?)`: Off-chain replica formula to calculate shares from stETH amount. - `getPooledEthByShares(sharesAmount, shareRateValues?)`: Off-chain replica formula to calculate stETH from shares amount. - `getPooledEthBySharesRoundUp(sharesAmount, shareRateValues?)`: Off-chain replica formula with ceiling rounding for calculating stETH from shares amount. ### Request Example ```ts import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; import { createPublicClient, http, createWalletClient, custom } from 'viem'; import { hoodi } from 'viem/chains'; const lidoSDK = new LidoSDK({ publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), chainId: 17000, walletClient: createWalletClient({ chain: hoodi, transport: custom(window.ethereum), }), }); // On-chain conversions const sharesValue = await lidoSDK.shares.convertToShares(1_000n); console.log('Shares Value:', sharesValue); const stethValue = await lidoSDK.shares.convertToSteth(1_000n); console.log('stETH Value:', stethValue); // Get share rate snapshot const shareRateValues = await lidoSDK.shares.getTotalSupply(); // Batch conversions const stethBatch = await lidoSDK.shares.convertBatchSharesToSteth( [100n, '200', { amount: 1_000_000_000_000_000_000n, roundUp: true }], shareRateValues, ); console.log('Batch stETH Conversion:', stethBatch); const sharesBatch = await lidoSDK.shares.convertBatchStethToShares( [100n, 200n, 300n], shareRateValues, ); console.log('Batch Shares Conversion:', sharesBatch); // Off-chain conversion with rounding const pooledEthRoundUp = await lidoSDK.shares.getPooledEthBySharesRoundUp( 1000n, shareRateValues, ); console.log('Pooled ETH (Round Up):', pooledEthRoundUp); ``` ``` -------------------------------- ### Build Static Website Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/README.md Generates static website content into the 'build' directory for hosting. ```bash yarn build ``` -------------------------------- ### Get Claimable Requests ETH By Account Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Retrieves ETH amounts, hints, and request details for all claimable withdrawals associated with an account. ```APIDOC ## GET /api/withdrawal/claimable/eth/by-account ### Description Retrieves ETH amounts, hints, and request details for all claimable withdrawals associated with an account. ### Method GET ### Endpoint /api/withdrawal/claimable/eth/by-account ### Parameters #### Query Parameters - **account** (Address | Account) - Required - The account address. ### Response #### Success Response (200) - **Type**: Object - **Structure**: - **ethByRequests** (Array[bigint]) - A list of ETH amounts for each request. - **ethSum** (bigint) - The sum of all ETH amounts in the list. - **hints** (Array[bigint]) - A list of hints for each request. - **requests** (Array[RequestStatusWithId]) - A list of requests with their statuses and identifiers. - **sortedIds** (Array[bigint]) - A list of request identifiers sorted by id. #### Response Example { "example": "{ "ethByRequests": ["1000000000000000000"], "ethSum": "1000000000000000000", "hints": [1], "requests": [ { "id": 12345, "isFinalized": true, "isClaimed": false, "amountOfStETH": "1000000000000000000", "amountOfShares": "1000000000000000000", "owner": "0x123...", "timestamp": 1678886400, "stringId": "12345" } ], "sortedIds": [12345] }" } ``` -------------------------------- ### Get Claimable Requests ETH By IDs Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/modules/withdraw.md Retrieves the ETH amounts and related hints for specific claimable withdrawal request IDs. ```APIDOC ## GET /api/withdrawal/claimable/eth/by-ids ### Description Retrieves the ETH amounts and related hints for specific claimable withdrawal request IDs. ### Method GET ### Endpoint /api/withdrawal/claimable/eth/by-ids ### Parameters #### Query Parameters - **claimableRequestsIds** (Array[bigint | RequestStatusWithId]) - Required - An array of request identifiers for which information is needed. ### Response #### Success Response (200) - **Type**: Object - **Structure**: - **ethByRequests** (Array[bigint]) - A list of ETH amounts for each request. - **ethSum** (bigint) - The sum of all ETH amounts in the list. - **hints** (Array[bigint]) - A list of hints for each request. #### Response Example { "example": "{ "ethByRequests": ["1000000000000000000"], "ethSum": "1000000000000000000", "hints": [1] }" } ``` -------------------------------- ### Initialize Separate SDK Modules Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/docs/sdk/get-started/usage.md Initialize individual SDK modules like Stake or Wrap. You can let the core be created under the hood or pass an existing LidoSDKCore instance. ```typescript import { LidoSDKStake } from '@lidofinance/lido-ethereum-sdk/stake'; import { LidoSDKWrap } from '@lidofinance/lido-ethereum-sdk/wrap'; import { LidoSDKCore } from '@lidofinance/lido-ethereum-sdk/core'; import { createWalletClient, custom, hoodi, http, createPublicClient, } from 'viem'; const params = { publicClient: createPublicClient({ chain: hoodi, transport: http(''), }), }; // core is created under the hood const stake = new LidoSDKStake(params); // or core is created separately and passed to modules individually const core = new LidoSDKCore(params); const wrap = new LidoSDKWrap({ core }); ``` -------------------------------- ### Navigate to Playground Directory Source: https://github.com/lidofinance/lido-ethereum-sdk/blob/develop/playground/README.md Change the current directory to the playground folder. ```bash cd playground ```