### Install starknet.js Source: https://docs.rhino.fi/contracts/starknet Install the starknet.js library using yarn or npm. ```bash yarn add starknet ``` ```bash npm install starknet ``` -------------------------------- ### Install the Rhino.fi SDK Source: https://docs.rhino.fi/sdk/quickstart Install the Rhino.fi SDK using your preferred package manager. ```bash npm install @rhino.fi/sdk ``` ```bash yarn add @rhino.fi/sdk ``` ```bash pnpm install @rhino.fi/sdk ``` ```bash bun install @rhino.fi/sdk ``` -------------------------------- ### Full Bridge Transaction Example Source: https://docs.rhino.fi/api-integration/bridge A complete implementation demonstrating the sequence of fetching configs, getting a quote, committing the quote, and preparing for smart contract execution. ```javascript import { getBridgeUserQuote } from "./getBridgeUserQuote"; import { getBridgeConfigs } from "./getBridgeConfigs"; import { commitBridgeUserQuote } from "./commitBridgeUserQuote"; const JWT = 'YOUR_JWT'; // Replace with your JWT generated from our API const amount = '3'; const chainIn = 'BASE'; const chainOut = 'SOLANA'; const token = 'USDT'; const depositorAddress = '0x0000000000000000000000000000000000000000'; // Replace with your depositor address const recipientAddress = '0x0000000000000000000000000000000000000000'; // Replace with your recipient address const bridge = async () => { // Get bridge configs to determine supported chains and tokens or later use for the contract call const configs = await getBridgeConfigs(); // Get a bridge quote for the transaction const quote = await getBridgeUserQuote({ amount, chainIn, chainOut, token, mode: 'receive', depositor: depositorAddress, recipient: recipientAddress, amountNative: '0' }, JWT); if (!quote?.quoteId) throw new Error('Failed to generate user quote.'); // Commit the quote to confirm the transaction when you are ready to send on-chain const commitResult = await commitBridgeUserQuote(quote.quoteId, JWT); if (!commitResult?.quoteId) throw new Error('Failed to commit user quote.'); const chainConfig = configs[chainIn]; // Execute the bridge transaction by interacting with the smart contract -- see contract examples section on exact implementation await callBridgeContract({ chainConfig, amount: quote.payAmount, token, commitmentId: commitResult.quoteId, callback: (hash) => console.info('Transaction hash:', hash) }); }; bridge(); ``` -------------------------------- ### Install TON Libraries Source: https://docs.rhino.fi/contracts/ton Install the necessary TON libraries for interacting with TON contracts. ```bash yarn add @ton/ton @ton/crypto ``` ```bash npm install @ton/ton @ton/crypto ``` -------------------------------- ### Install tronweb Source: https://docs.rhino.fi/contracts/tron Install the tronweb library using either yarn or npm to interact with the Tron network. ```bash yarn add tronweb ``` ```bash npm install tronweb ``` -------------------------------- ### Install Solana Dependencies Source: https://docs.rhino.fi/contracts/solana Install the necessary Solana libraries for interacting with the bridge contract. Use yarn or npm. ```bash yarn add @solana/web3.js @solana/spl-token @coral-xyz/anchor ``` ```bash npm install @solana/web3.js @solana/spl-token @coral-xyz/anchor ``` -------------------------------- ### Install ethers.js with npm Source: https://docs.rhino.fi/contracts/evm Install the ethers.js library using npm for interacting with EVM contracts. ```bash npm install ethers ``` -------------------------------- ### Install ethers.js with Yarn Source: https://docs.rhino.fi/contracts/evm Install the ethers.js library using Yarn for interacting with EVM contracts. ```bash yarn add ethers ``` -------------------------------- ### Create Starknet Chain Adapter from Private Key Source: https://docs.rhino.fi/sdk/chain-adapters/starknet This method provides a shortcut for setting up a Starknet account using your private key and address. It requires your private key, address, and chain configuration. ```typescript import { getStarknetChainAdapterFromPrivateKey } from '@rhino.fi/sdk/adapters/starknet' const chainAdapter = getStarknetChainAdapterFromPrivateKey({ privateKey: 'YOUR_PRIVATE_KEY', address: 'YOUR_ADDRESS', chainConfig, }) ``` -------------------------------- ### Interact with EVM Chain Adapters using SDK Source: https://docs.rhino.fi/sdk/migration-guides/from-api This snippet demonstrates setting up an EVM chain adapter, checking for token approvals, handling approvals if necessary, and then managing the deposit transaction. ```typescript // Set up the chain adapter, can be any of the included ones const evmChainAdapter = getEvmChainAdapterFromPrivateKey( 'YOUR_PRIVATE_KEY', chainConfig ) // Check if a token approval is needed. Could be skipped if you know that the blockchain does not have a concept of token approvals, like Solana. const approvalAmount = await evmChainAdapter.getApprovalAmount(depositAmount, walletAddress, tokenConfig) if(approvalAmount) { // Set up the token approval if needed await evmChainAdapter.handleTokenApproval(approvalAmount, tokenConfig) } // Send the funds to be bridged to the bridge contract. Once successful, the status // of the bridge can be tracked through the Rhino API as usual. const { depositTxHash } = await evmChainAdapter.handleDeposit({ tokenConfig, depositAmount, commitmentId, }) ``` -------------------------------- ### Full Bridge and Swap Example in JavaScript Source: https://docs.rhino.fi/api-integration/swap This snippet shows the complete implementation for a cross-chain swap. It requires JWT authentication and specific parameters for input/output chains and tokens. Ensure you replace placeholder values with your actual JWT and addresses. ```javascript import { getBridgeSwapUserQuote } from "./getBridgeSwapUserQuote"; import { getBridgeConfigs } from "./getBridgeConfigs"; import { getSwapTokenConfig } from "./getSwapTokenConfig"; import { commitBridgeSwapUserQuote } from "./commitBridgeSwapUserQuote"; const JWT = 'YOUR_JWT'; // Replace with your JWT generated from our API const amount = '1'; const chainIn = 'BASE'; const chainOut = 'ARBITRUM'; const tokenIn = 'USDT'; const tokenOut = 'USDC'; const depositorAddress = '0x0000000000000000000000000000000000000000'; // Replace with your depositor address const recipientAddress = '0x0000000000000000000000000000000000000000'; // Replace with your recipient address const bridgeAndSwap = async () => { // Get bridge configs to determine supported chains and tokens or later use for the contract call const configs = await getBridgeConfigs(); const swapTokenConfig = await getSwapTokenConfig(); // Get a bridge quote for the transaction const quote = await getBridgeSwapUserQuote({ amount, chainIn, chainOut, tokenIn, tokenOut, mode: 'pay', depositor: depositorAddress, recipient: recipientAddress, amountNative: '0' }, JWT); if (!quote?.quoteId) throw new Error('Failed to generate user quote.'); // Commit the quote to confirm the transaction when you are ready to send on-chain const commitResult = await commitBridgeSwapUserQuote(quote.quoteId, JWT); if (!commitResult?.quoteId) throw new Error('Failed to commit user quote.'); const chainConfig = configs[chainIn]; const swapConfig = swapTokenConfig[chainIn][tokenIn]; // Execute the bridge transaction by interacting with the smart contract -- see contract examples section on exact implementation await callBridgeContract({ chainConfig, swapConfig, amount: quote.payAmount, tokenIn, commitmentId: commitResult.quoteId, callback: (hash) => console.info('Transaction hash:', hash) }); }; bridgeAndSwap(); ``` -------------------------------- ### SDA Widget Theming Example Source: https://docs.rhino.fi/widget/sda-widget Example of embedding the SDA Widget with a custom theme applied via URL query parameters. The theme is provided as a URL-encoded JSON object. ```html