Skip to main content

Overview

The GnosisBridgeFacet enables bridging of ETH and ERC20 tokens from Ethereum mainnet to Gnosis Chain (formerly xDai Chain) using the official Gnosis bridge infrastructure.

Contract Interface

Functions

startBridgeTokensViaGnosisBridge

Bridges tokens from Ethereum to Gnosis Chain.
function startBridgeTokensViaGnosisBridge(
  BridgeData _bridgeData
) external
_bridgeData
BridgeData
Standard bridge data containing transaction details

swapAndStartBridgeTokensViaGnosisBridge

Performs a token swap on Ethereum before bridging to Gnosis Chain.
function swapAndStartBridgeTokensViaGnosisBridge(
  BridgeData _bridgeData,
  SwapData[] _swapData
) external payable
_bridgeData
BridgeData
Standard bridge data
_swapData
SwapData[]
Array of swap operations to execute before bridging

Usage Example

Bridging DAI to Gnosis (becomes xDai)

import { GnosisBridgeFacet } from '@lifi/contract-types';

const gnosisFacet = GnosisBridgeFacet__factory.connect(facetAddress, signer);

const bridgeData = {
  transactionId: ethers.utils.randomBytes(32),
  bridge: 'gnosis',
  integrator: 'my-dapp',
  referrer: '0x0000000000000000000000000000000000000000',
  sendingAssetId: '0x6B175474E89094C44Da98b954EedeAC495271d0F', // DAI on Ethereum
  receiver: await signer.getAddress(),
  minAmount: ethers.utils.parseUnits('100', 18),
  destinationChainId: 100, // Gnosis Chain
  hasSourceSwaps: false,
  hasDestinationCall: false
};

// Approve DAI first
const dai = new ethers.Contract(
  bridgeData.sendingAssetId,
  ['function approve(address spender, uint256 amount) returns (bool)'],
  signer
);

await dai.approve(gnosisFacet.address, bridgeData.minAmount);

// Bridge DAI to xDai
const tx = await gnosisFacet.startBridgeTokensViaGnosisBridge(bridgeData);

await tx.wait();

console.log('DAI bridged. Will arrive as xDai on Gnosis Chain.');

Bridging ERC20 Tokens

const bridgeData = {
  transactionId: ethers.utils.randomBytes(32),
  bridge: 'gnosis',
  integrator: 'my-dapp',
  referrer: '0x0000000000000000000000000000000000000000',
  sendingAssetId: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
  receiver: await signer.getAddress(),
  minAmount: ethers.utils.parseUnits('1000', 6),
  destinationChainId: 100,
  hasSourceSwaps: false,
  hasDestinationCall: false
};

// Approve USDC
const usdc = new ethers.Contract(
  bridgeData.sendingAssetId,
  ['function approve(address spender, uint256 amount) returns (bool)'],
  signer
);

await usdc.approve(gnosisFacet.address, bridgeData.minAmount);

// Bridge tokens
const tx = await gnosisFacet.startBridgeTokensViaGnosisBridge(bridgeData);

await tx.wait();

Swap and Bridge

const swapData = [{
  callTo: uniswapRouter,
  approveTo: uniswapRouter,
  sendingAssetId: wethAddress,
  receivingAssetId: daiAddress,
  fromAmount: ethers.utils.parseEther('1'),
  callData: swapCalldata,
  requiresDeposit: true
}];

const bridgeData = {
  transactionId: ethers.utils.randomBytes(32),
  bridge: 'gnosis',
  integrator: 'my-dapp',
  referrer: '0x0000000000000000000000000000000000000000',
  sendingAssetId: daiAddress,
  receiver: await signer.getAddress(),
  minAmount: ethers.utils.parseUnits('1800', 18), // Min DAI expected
  destinationChainId: 100,
  hasSourceSwaps: true,
  hasDestinationCall: false
};

const tx = await gnosisFacet.swapAndStartBridgeTokensViaGnosisBridge(
  bridgeData,
  swapData
);

await tx.wait();

Events

  • LiFiTransferStarted(BridgeData bridgeData) - Emitted when bridge transfer is initiated
  • LiFiTransferCompleted - Emitted when transfer completes
  • AssetSwapped - Emitted when using swapAndStart variant

Notes

  • This facet only supports bridging FROM Ethereum mainnet TO Gnosis Chain
  • DAI bridged to Gnosis becomes xDai (the native gas token)
  • Other ERC20 tokens are bridged to their wrapped/mapped versions on Gnosis
  • Bridging typically takes a few minutes for finality
  • The bridge uses the Arbitrary Message Bridge (AMB) for ERC20 tokens
  • Tokens must be approved before bridging

Token Bridging

DAI → xDai

DAI from Ethereum becomes xDai (native token) on Gnosis Chain with 1:1 ratio.

Other ERC20 Tokens

ERC20 tokens are bridged using the OmniBridge, creating wrapped versions on Gnosis Chain.

Bridge Times

  • Ethereum → Gnosis: ~5 minutes
  • Gnosis → Ethereum: ~5 minutes + challenge period

See Also

Build docs developers (and LLMs) love