Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.rhinestone.dev/llms.txt

Use this file to discover all available pages before exploring further.

You can specify the exact amount of source (input) tokens to spend for the bridging. This can be helpful if you want to limit the amount of tokens to bridge, or if you want to bridge the entire token balance. To bridge a specific amount of tokens:
const transaction = await rhinestoneAccount.prepareTransaction({
  sourceChains: [optimism],
  targetChain: base,
  sourceAssets: [
    {
      chain: optimism,
      address: 'USDC',
      amount: parseUnits('10', 6),
    }
  ],
  tokenRequests: [
    {
      // Note: no amount specified for the target token
      address: 'USDC',
    },
  ],
})
This will bridge 10 USDC from Optimism to Base.

Entire Balance

To bridge the entire balance of a token:
const sourceChain = optimism
const targetChain = base
const usdcOnOptimism = '0x0b2c639c533813F4AA9D7837CAF62653d097Ff85'

const publicClient = createPublicClient({
  chain: sourceChain,
  transport: http(),
})
const usdcBalance = await publicClient.readContract({
  address: usdcOnOptimism,
  abi: erc20Abi,
  functionName: 'balanceOf',
  args: [address],
})

const transaction = await rhinestoneAccount.prepareTransaction({
  sourceChains: [sourceChain],
  targetChain,
  sourceAssets: [
    {
      chain: sourceChain,
      address: 'USDC',
      amount: usdcBalance,
    },
  ],
  tokenRequests: [
    {
      address: 'USDC',
    },
  ],
})
This will sweep the user’s USDC balance on Optimism to Base.

Multichain

You can specify exact source amounts from multiple source chains:
const transaction = await rhinestoneAccount.prepareTransaction({
  sourceChains: [optimism, base],
  targetChain: arbitrum,
  sourceAssets: [
    {
      chain: optimism,
      address: 'USDC',
      amount: parseUnits('50', 6),
    },
    {
      chain: base,
      address: 'USDC',
      amount: parseUnits('30', 6),
    },
  ],
  tokenRequests: [
    {
      address: 'USDC',
    },
  ],
})
This will bridge 50 USDC from Optimism and 30 USDC from Base to Arbitrum, combining them into a single balance on the target chain.