Skip to main content

BridgeNFT

The BridgeNFT class facilitates the bridging of non-fungible tokens across different chains.

To bridge any holographic asset to another network, a three-step process is followed:

  1. Bridge Out - Users initiate a bridge out request to the HolographBridge contract on the source chain.
  2. Message Layer - The message layer is responsible for transmitting the message from the source chain to the destination chain.
  3. Bridge In - Once the message layer successfully delivers the message, the HolographBridge contract on the destination chain finalizes the bridging process.

This class provides the bridgeOut function, which initiates the entire bridging process.

1. Constructor Parameters

holographConfig

  • Type:
    HolographConfigrequired

The HolographConfig object that will be used to bridge the NFT.

src/holograph/config.ts
import { HolographAccountFactory, HolographConfig } from "@holographxyz/sdk";
import { Environment } from "@holographxyz/environment";

export const defaultAccount =
HolographAccountFactory.createAccountUsingPrivateKey(process.env.PRIVATE_KEY);

export const holographConfig: HolographConfig = {
networks: {
ethereum: "https://your-ethereum-rpc-url.com",
polygon: "https://your-polygon-rpc-url.com",
avalanche: "https://your-avalanche-rpc-url.com",
},
environment: Environment.mainnet,
accounts: {
default: defaultAccount,
},
};

bridgeNFTInput

  • Type:
    BridgeNFTInputrequired

The input object containing all the information to bridge the NFT.

type BridgeNFTInput = {
sourceChainId: number
destinationChainId: number
contractAddress: `0x${string}`
tokenId: `0x${string}`
from?: `0x${string}`
to?: `0x${string}`
wallet: HolographWallet
}
  • Validation:
    • sourceChainId:
      numberrequired
      - must be the chain ID where the NFT is located.
    • destinationChainId:
      numberrequired
      - must be a chain ID of a network to which the NFT contract is already deployed.
    • contractAddress:
      0x${string}required
      - must be the NFT contract address.
    • tokenId:
      0x${string}required
      - must be the NFT token ID.
    • from:
      0x${string}default: wallet.account.address
      - must be the NFT owner's address.
    • to:
      0x${string}default: from
      - must be the NFT owner's address or another address to transfer ownership.
    • wallet:
      HolographWalletrequired
      - must be the wallet that is going to execute the transaction.

gasSettings

  • Type:
    GasSettings

This is an optional input object that allows users to override the source gasPrice and gasLimit in Wei, providing greater control over these values.

type GasSettings = {
gasPrice?: bigint
gasLimit?: bigint
}

Example:

src/holograph/bridge-nft.ts
import { BridgeNFT } from "@holographxyz/sdk"
import { networks } from "@holographxyz/networks"

import { holographConfig, wallet } from "./config"
import { myContract } from "./collection"
import { myNFT } from "./nft"

const bridgeNFT = new BridgeNFT(holographConfig, {
sourceChainId: myContract.primaryChainId,
destinationChainId: networks.ethereum.chain,
contractAddress: myContract.collectionAddress,
tokenId: myNFT.tokenId,
wallet,
}, {
gasPrice: BigInt(132000000000),
gasLimit: BigInt(650000)
})

For further details on NFT and contract features, please refer to the following resources:


2. Properties

contractAddress

  • Type:
    0x${string}

The NFT contract address.

tokenId

  • Type:
    0x${string}

The NFT token ID hex string.

from

  • Type:
    0x${string}

The address of the NFT owner on the source chain.

to

  • Type:
    0x${string}

The address of the wallet to which the NFT will be transferred on the destination chain.

destinationChainId

  • Type:
    number

The chain ID of a network to which the NFT is being bridged.

sourceChainId

  • Type:
    number

The chain ID where the NFT is located.


3. Methods

createInitCode()

This is a static class method utilized by the getInitCode and can also be invoked without instantiating the class. It returns the bridge out payload.

Params:

  • from:
    0x${string}required
    - The address of the NFT owner on the source chain.
  • to:
    0x${string}required
    - The address of the wallet to which the NFT will be transferred on the destination chain.
  • tokenId:
    0x${string}required
    - The NFT token ID hex string.

Returns:

Promise<0x${string}>

Example:

import { BridgeNFT } from "@holographxyz/sdk"

const from = "0xB1113E02F232d00bCf060c2c70A9b60d09309501"
const to = "0xB1113E02F232d00bCf060c2c70A9b60d09309501"
const tokenId = "0x0000000000000000000000000000000000000000000000000000000000000001"

const bridgeOutPayload = await BridgeNFT.createInitCode(from, to, tokenId)

getInitCode()

Retrieve the initialization payload required for the bridgeOut function. This hexadecimal string encodes from, to, and tokenId parameters.

Returns:

Promise<0x${string}>

Example:

 const bridgeOutPayload = await bridgeNFT.getInitCode()

bridgeOut()

Makes the bridgeOut request.

Params:

  • walletOverride:
    HolographWallet
    - The option overrides the configured wallet.
  • destinationChainId:
    number
    - The option overrides the configured destination chain.

Returns:

Promise<Transaction>

Example:

import { wallet } from "./config"

const tx = await bridgeNFT.bridgeOut(wallet)