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

bridgeNFTInput

  • Type:
    BridgeNFTInputrequired

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

type BridgeNFTInput = {
sourceChainId: number
destinationChainId: number
contractAddress: `0x${string}`
wallet: HolographWallet
tokenId: `0x${string}`
from?: `0x${string}`
to?: `0x${string}`
}
  • 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.
    • wallet:
      HolographWalletrequired
      - must be the wallet that is going to execute the transaction.
    • 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.

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 { wallet } from "./config"
import { myContract } from "./contract"
import { myNFT } from "./nft"

const bridgeNFT = new BridgeNFT(
{
sourceChainId: myContract.primaryChainId,
destinationChainId: networks.ethereum.chain,
contractAddress: myContract.contractAddress,
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 envoked 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)