### Install Dependencies Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Installs project dependencies using pnpm. Ensure you have Node.js and pnpm installed. ```bash pnpm install ``` -------------------------------- ### Install Core SDK with npm Source: https://github.com/lifinance/sdk/blob/main/README.md Install the core LI.FI SDK package using npm. ```bash npm install --save @lifi/sdk ``` -------------------------------- ### Install Core SDK with pnpm Source: https://github.com/lifinance/sdk/blob/main/README.md Install the core LI.FI SDK package using pnpm. ```bash pnpm add @lifi/sdk ``` -------------------------------- ### Install Bitcoin Provider Package Source: https://github.com/lifinance/sdk/blob/main/README.md Install the provider package for the Bitcoin blockchain ecosystem. ```bash pnpm add @lifi/sdk-provider-bitcoin ``` -------------------------------- ### Core SDK Installation Source: https://github.com/lifinance/sdk/blob/main/README.md Install the core LI.FI SDK package using npm or pnpm. ```bash pnpm add @lifi/sdk or npm install --save @lifi/sdk ``` -------------------------------- ### Set up SDK for EVM Chains Source: https://github.com/lifinance/sdk/blob/main/README.md Configure the LI.FI SDK client for EVM chains, including wallet client setup and provider configuration. Ensure you add your account using appropriate viem functions. ```typescript import { createClient } from '@lifi/sdk' import { EthereumProvider } from '@lifi/sdk-provider-ethereum' import { createWalletClient, http } from 'viem' import { mainnet } from 'viem/chains' // Add your account (e.g. privateKeyToAccount, mnemonicToAccount) const walletClient = createWalletClient({ account, chain: mainnet, transport: http(), }) const client = createClient({ integrator: 'Your dApp/company name', providers: [ EthereumProvider({ getWalletClient: () => Promise.resolve(walletClient), }), ], }) ``` -------------------------------- ### Install Tron Provider Package Source: https://github.com/lifinance/sdk/blob/main/README.md Install the provider package for the Tron blockchain ecosystem. ```bash pnpm add @lifi/sdk-provider-tron ``` -------------------------------- ### Install Sui Provider Package Source: https://github.com/lifinance/sdk/blob/main/README.md Install the provider package for the Sui blockchain ecosystem. ```bash pnpm add @lifi/sdk-provider-sui ``` -------------------------------- ### Install Solana Provider Package Source: https://github.com/lifinance/sdk/blob/main/README.md Install the provider package for the Solana blockchain ecosystem. ```bash pnpm add @lifi/sdk-provider-solana ``` -------------------------------- ### Install EVM Provider Package Source: https://github.com/lifinance/sdk/blob/main/README.md Install the provider package for EVM-compatible chains like Ethereum, Polygon, and Arbitrum. ```bash pnpm add @lifi/sdk-provider-ethereum ``` -------------------------------- ### Provider Packages Installation Source: https://github.com/lifinance/sdk/blob/main/README.md Install provider packages for specific blockchain ecosystems you wish to support. ```bash # EVM Chains pnpm add @lifi/sdk-provider-ethereum # Solana pnpm add @lifi/sdk-provider-solana # Bitcoin pnpm add @lifi/sdk-provider-bitcoin # Sui pnpm add @lifi/sdk-provider-sui # Tron pnpm add @lifi/sdk-provider-tron ``` -------------------------------- ### Multi-Hop Bridge Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Demonstrates a complex bridging scenario involving multiple bridges and intermediate chains. It gets a quote for the second bridge leg and creates contract calls for bridging and execution. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function multiHopExample() { const provider = new Provider("ethereum"); const client = createClient({ provider }); // Get a quote for the second bridge leg (Polygon -> Optimism) const quote = await client.getQuote({ fromChainId: 137, // Polygon toChainId: 10, // Optimism fromTokenAddress: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", // MATIC toTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC fromAmount: "1000000000000000000", // 1 MATIC }); // Create a contract calls quote that bridges to Polygon AND executes the second bridge const contractCallsQuote = await client.getContractCallsQuote({ fromChainId: 42161, // Arbitrum toChainId: 10, // Optimism fromTokenAddress: "0xaf84175133660637766033037873793451189670", // USDC on Arbitrum toTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC on Optimism fromAmount: "1000000000000000000", // 1 USDC contractCalls: [ { toChainId: quote.toChainId, toAmount: quote.toAmount, toTokenAddress: quote.toTokenAddress, contractAddress: quote.contractAddress, contractCallData: quote.callData, }, ], }); // Manually send the transaction and poll for status const { transaction } = await client.executeRoute({ route: contractCallsQuote.routes[0], }); await transaction?.wait(); // Poll for status let status = await client.getStatus({ chainId: contractCallsQuote.routes[0].toChainId, txHash: transaction.hash, }); while (status !== "DONE") { await new Promise((resolve) => setTimeout(resolve, 5000)); status = await client.getStatus({ chainId: contractCallsQuote.routes[0].toChainId, txHash: transaction.hash }); console.log(`Status: ${status}`); } console.log("Multi-hop bridge executed successfully!"); } multiHopExample(); ``` -------------------------------- ### Set up SDK for Multiple Ecosystems Source: https://github.com/lifinance/sdk/blob/main/README.md Configure the LI.FI SDK client to support multiple blockchain ecosystems by including their respective provider packages. ```typescript import { createClient } from '@lifi/sdk' import { EthereumProvider } from '@lifi/sdk-provider-ethereum' import { SolanaProvider } from '@lifi/sdk-provider-solana' import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin' import { SuiProvider } from '@lifi/sdk-provider-sui' import { TronProvider } from '@lifi/sdk-provider-tron' const client = createClient({ integrator: 'Your dApp/company name', providers: [ EthereumProvider({ /* options */ }), SolanaProvider({ /* options */ }), BitcoinProvider({ /* options */ }), SuiProvider({ /* options */ }), TronProvider({ /* options */ }), ], }) ``` -------------------------------- ### Same-Chain Token Swap Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Demonstrates a basic token swap on a single chain using getRoutes and executeRoute. Initializes the SDK client and requests a route for a USDC to USDT swap on Optimism. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function swapExample() { const provider = new Provider("ethereum"); // Use EthereumProvider for EVM chains const client = createClient({ provider }); // Request a route for USDC to USDT swap on Optimism const routes = await client.getRoutes({ fromChainId: 10, // Optimism toChainId: 10, // Optimism fromTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC toTokenAddress: "0x4200000000000000000000000000000000000006", // USDT fromAmount: "1000000000000000000", // 1 USDC }); // Execute the first route const { transaction } = await client.executeRoute({ route: routes.routes[0] }); // Wait for the transaction to be completed await transaction?.wait(); console.log("Swap executed successfully!"); } swapExample(); ``` -------------------------------- ### Request a Quote from SDK Source: https://github.com/lifinance/sdk/blob/main/README.md Use the LI.FI SDK to request a quote for a cross-chain transaction. Ensure the client is properly configured with providers. ```typescript import { ChainId, getQuote } from '@lifi/sdk' const quote = await getQuote(client, { fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', fromChain: ChainId.ARB, toChain: ChainId.OPT, fromToken: '0x0000000000000000000000000000000000000000', toToken: '0x0000000000000000000000000000000000000000', fromAmount: '1000000000000000000', }) ``` -------------------------------- ### Exact Output Amount Bridge Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Demonstrates bridging with a specific target output amount, performing a reverse quote calculation. The SDK calculates the required input amount, and the transaction is executed manually. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function toAmountExample() { const provider = new Provider("ethereum"); const client = createClient({ provider }); // Request a quote where toAmount is specified instead of fromAmount const quote = await client.getContractCallsQuote({ fromChainId: 42161, // Arbitrum toChainId: 10, // Optimism fromTokenAddress: "0xaf84175133660637766033037873793451189670", // USDC on Arbitrum toTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC on Optimism toAmount: "1000000000000000000", // Target 1 USDC on Optimism }); // Execute the transaction manually const { transaction } = await client.executeRoute({ route: quote.routes[0], }); await transaction?.wait(); console.log("Bridge with exact output amount executed successfully!"); } toAmountExample(); ``` -------------------------------- ### Cross-Chain Token Bridge Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Illustrates bridging tokens between two different chains, including automatic chain switching. Initializes the SDK client with a switchChain callback for multi-chain support. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function bridgeExample() { const provider = new Provider("ethereum", { // Handle chain switching during execution switchChain: async (chainId) => { await window.ethereum.request({ method: "wallet_switchEthereumChain", params: [{ chainId: `0x${chainId.toString(16)}` }], }); }, }); const client = createClient({ provider }); // Request a route for USDC bridge from Optimism to Arbitrum const routes = await client.getRoutes({ fromChainId: 10, // Optimism toChainId: 42161, // Arbitrum fromTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC toTokenAddress: "0xaf84175133660637766033037873793451189670", // USDC on Arbitrum fromAmount: "1000000000000000000", // 1 USDC }); // Execute the bridge with automatic chain switching if needed const { transaction } = await client.executeRoute({ route: routes.routes[0] }); // Wait for the transaction to be completed await transaction?.wait(); console.log("Bridge executed successfully!"); } bridgeExample(); ``` -------------------------------- ### DeFi Protocol Deposit Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Illustrates a cross-chain deposit into a Polynomial Earn vault. Encodes the initiateDeposit function call and creates a quote to bridge tokens and deposit in one transaction. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function polynomialDepositExample() { const provider = new Provider("ethereum"); const client = createClient({ provider }); // Encodes initiateDeposit function call for Polynomial contract const contractCallsQuote = await client.getContractCallsQuote({ fromChainId: 42161, // Arbitrum toChainId: 10, // Optimism fromTokenAddress: "0xaf84175133660637766033037873793451189670", // USDC on Arbitrum toTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC on Optimism fromAmount: "1000000000000000000", // 1 USDC contractCalls: [ { toChainId: 10, // Optimism toAmount: "0", // Not used for contract calls toTokenAddress: "0x4200000000000000000000000000000000000006", // USDT on Optimism (example) contractAddress: "0xYourPolynomialVaultAddress", // Replace with actual Polynomial Vault address on Optimism // initiateDeposit(address user, uint256 amount, address token) functionSignature: "initiateDeposit(address,uint256,address)", parameters: [ "0xYourWalletAddress", // Replace with the actual user address "1000000000000000000", // Amount to deposit "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC on Optimism ], }, ], }); // Creates quote to bridge sETH to Optimism and deposit in one transaction const { transaction } = await client.executeRoute({ route: contractCallsQuote.routes[0], }); await transaction?.wait(); console.log("DeFi deposit executed successfully!"); } polynomialDepositExample(); ``` -------------------------------- ### Carbon Offset Integration Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Shows a cross-chain contract call to Klima DAO for carbon retirement. Encodes the retireExactCarbonDefault function call and creates a quote to bridge tokens and retire carbon in one transaction. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function klimaRetireExactCarbonExample() { const provider = new Provider("ethereum"); const client = createClient({ provider }); // Read Klima contract to calculate required token amount (example values) const requiredTokenAmount = "1000000000000000000"; // Example amount // Encode the retireExactCarbonDefault function call const contractCallsQuote = await client.getContractCallsQuote({ fromChainId: 10, // Optimism toChainId: 137, // Polygon fromTokenAddress: "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC on Optimism toTokenAddress: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", // MATIC on Polygon (as an example token to bridge) fromAmount: requiredTokenAmount, contractCalls: [ { toChainId: 137, // Polygon toAmount: "0", // Not used for contract calls toTokenAddress: "0x41996f3917353756474792317877448033727361", // KLIMA Token Address on Polygon contractAddress: "0x9793797247063312685746873438347377797051", // Klima Retirement Aggregator Address on Polygon // retireExactCarbonDefault(uint256 amount, address tokenToBurn, address to) // Example: retire 1 KLIMA, burn USDC, retire for yourself functionSignature: "retireExactCarbonDefault(uint256,address,address)", // Parameters: amount, tokenToBurn, to (address of the user) // Note: The actual tokenToBurn and amount might need to be calculated based on Klima's logic. // This is a simplified example. parameters: [ "1000000000000000000", // 1 KLIMA "0x7F5c764cBc14f9669B901195279dc6471B936079", // USDC on Optimism (example token to burn) "0xYourWalletAddress", // Replace with the actual recipient address ], }, ], }); // Execute and monitor the transaction const { transaction } = await client.executeRoute({ route: contractCallsQuote.routes[0], }); await transaction?.wait(); let status = await client.getStatus({ chainId: contractCallsQuote.routes[0].toChainId, txHash: transaction.hash, }); while (status !== "DONE") { await new Promise((resolve) => setTimeout(resolve, 5000)); status = await client.getStatus({ chainId: contractCallsQuote.routes[0].toChainId, txHash: transaction.hash }); console.log(`Status: ${status}`); } console.log("Carbon offset executed successfully!"); } klimaRetireExactCarbonExample(); ``` -------------------------------- ### Yearn Vault Deposit Source: https://github.com/lifinance/sdk/blob/main/examples/node/README.md Demonstrates a cross-chain deposit into a Yearn Finance vault. Encodes the deposit function call and creates a quote to bridge WETH to Polygon and deposit. ```typescript import { createClient, Provider } from "@lifi/sdk"; async function yearnDepositExample() { const provider = new Provider("ethereum"); const client = createClient({ provider }); // Encodes deposit function call for Yearn vault const contractCallsQuote = await client.getContractCallsQuote({ fromChainId: 42161, // Arbitrum toChainId: 137, // Polygon fromTokenAddress: "0x82aF49440F8971fBC28557054A84A6f897771041", // WETH on Arbitrum toTokenAddress: "0x7c1d3b3cc677903d5727747032186111f177c9c2", // WETH on Polygon fromAmount: "1000000000000000000", // 1 WETH contractCalls: [ { toChainId: 137, // Polygon toAmount: "0", // Not used for contract calls toTokenAddress: "0x7c1d3b3cc677903d5727747032186111f177c9c2", // WETH on Polygon contractAddress: "0x9d4074331615761587433437708134776760751f", // Yearn Vault Address on Polygon (example) // deposit(uint256 amount) functionSignature: "deposit(uint256)", parameters: [ "1000000000000000000", // Amount to deposit ], }, ], }); // Creates quote to bridge WETH to Polygon and deposit const { transaction } = await client.executeRoute({ route: contractCallsQuote.routes[0], }); await transaction?.wait(); // Conditional status polling (skipped for same-chain) let status = await client.getStatus({ chainId: contractCallsQuote.routes[0].toChainId, txHash: transaction.hash, }); while (status !== "DONE") { await new Promise((resolve) => setTimeout(resolve, 5000)); status = await client.getStatus({ chainId: contractCallsQuote.routes[0].toChainId, txHash: transaction.hash }); console.log(`Status: ${status}`); } console.log("Yearn vault deposit executed successfully!"); } yearnDepositExample(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.