Skip to main content

Bridging Tokens

Learn how to bridge omnichain tokens using Holograph SDK. This feature enables contracts, fungible, and non-fungible tokens to be bridged between different chains. To learn how to bridge, refer to the following sections:


Bridging NFTs

To bridge NFTs using the Holograph SDK, make sure to have the following prerequisites.

Prerequisites

To get the most out of this guide, make sure to:


1. Instantiate BridgeNFT Class

Create an instance of the BridgeNFT class, specifying the necessary parameters. Pay attention to the following:

  • Ensure that the contract exists on the destinationChainId and the sourceChainId. To bridge an NFT, the contract must be deployed to at least two chains.
src/holograph/bridge-nft.ts
import { BridgeNFT } from "@holographxyz/sdk"
import { networks } from "@holographxyz/networks"

import { wallet } from "./config"

const bridgeNFT = new BridgeNFT({
sourceChainId: myContract.primaryChainId,
destinationChainId: networks.ethereum.chain,
contractAddress: "0x1234567890abcdef1234567890abcdef12345678",
tokenId: "0x0000000000000000000000000000000000000000000000000000000000000001",
wallet,
})

2. Make Bridge Out Request

Call the bridgeOut function.

src/holograph/bridge-nft.ts
const bridgeOutNFTTx = await bridgeNFT.bridgeOut()

For more information, check out the BridgeNFT class reference.


Bridging Contracts

To bridge contracts with the Holograph SDK, make sure to have the following prerequisites.

Prerequisites

To get the most out of this guide, make sure to:


1. Instantiate BridgeContract Class

Create an instance of the BridgeContract class, specifying the necessary parameters. The erc721DeploymentConfig contains all the necessary information of a contract. This information remains the same across all networks.

src/holograph/bridge-contract.ts
import { BridgeContract } from "@holographxyz/sdk"

import { wallet } from "./config"
import { myContract } from "./deploy"

const erc721DeploymentConfig = myContract.createErc721DeploymentConfig(
wallet.account.address
)

const bridgeContract = new BridgeContract({
sourceChainId: myContract.primaryChainId,
contractAddress: myContract.contractAddress,
erc721DeploymentConfig,
wallet,
})

2. Make Bridge Out Request

Call the bridgeOut function, providing the destinationChainId of the desired network. Pay attention to the following:

  • Ensure the destinationChainId is one of the supported chains enabled by Holograph for bridges.
src/holograph/bridge-contract.ts
import { networks } from "@holographxyz/networks"

const destinationChainId = networks.polygon.chain

const bridgeOutContractTx = await bridgeContract.bridgeOut(destinationChainId)

For more information, check out the BridgeContract class reference.


Bridging Fungible Tokens

To bridge fungible tokens with the Holograph SDK, make sure to have the following prerequisites.

Prerequisites

To get the most out of this guide, make sure to:


1. Instantiate BridgeERC20 Class

Create an instance of the BridgeERC20 class, specifying the necessary parameters. Pay attention to the following:

  • Ensure that the contract exists on the destinationChainId and the sourceChainId. To bridge a fungible token, its contract must be deployed to at least two chains.
src/holograph/bridge-erc20.ts
import { BridgeERC20 } from "@holographxyz/sdk"
import { networks } from "@holographxyz/networks"

import { wallet } from "./config"

const bridgeFungibleToken = new BridgeERC20({
sourceChainId: networks.polygon.chain,
destinationChainId: networks.avalanche.chain,
contractAddress: "0x1234567890abcdef1234567890abcdef12345678", // ERC20 token contract address.
amount: BigInt(100000),
wallet,
})

2. Make Bridge Out Request

Call the bridgeOut function:

src/holograph/bridge-erc20.ts
const bridgeOutFungibleTokenTx = await bridgeFungibleToken.bridgeOut()

For more information, check out the BridgeERC20 class reference.