Skip to main content

BridgeCollection

The BridgeCollection class facilitates the bridging of holographic contract across different chains.

To bridge any holographic contract 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 contract.

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,
},
};

bridgeCollectionInput

  • Type:
    BridgeCollectionInputrequired

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

type DeploymentConfig = {
contractType: `0x${string}`
chainType: number
salt: `0x${string}`
byteCode: `0x${string}`
initCode: `0x${string}`
}

type BridgeCollectionInput = {
sourceChainId: number
contractAddress: `0x${string}`
erc721DeploymentConfig: DeploymentConfig
wallet: HolographWallet
}
  • Validation:
    • sourceChainId:
      numberrequired
      - must be the chain ID where the NFT is located.
    • contractAddress:
      0x${string}required
      - must be the contract address.
    • erc721DeploymentConfig:
      DeploymentConfigrequired
      - must be contract deployment config.
    • wallet:
      HolographWalletrequired
      - must be the wallet that owns the collecton and 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-collection.ts
import {HolographLegacyCollection, NFT, BridgeCollection } from "@holographxyz/sdk"

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

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

const bridgeContract = new BridgeCollection(holographConfig, {
sourceChainId: myContract.primaryChainId,
contractAddress: myContract.collectionAddress,
erc721DeploymentConfig,
wallet,
},{
gasPrice: BigInt(132000000000),
gasLimit: BigInt(650000)
})

For further details on collection features, please refer to the following resource:


2. Properties

sourceChainId

  • Type:
    number

The chain ID where the contract is located.

contractAddress

  • Type:
    0x${string}

The contract address.

account

  • Type:
    0x${string}

The configured wallet address.

erc721DeploymentConfig

  • Type:
    DeploymentConfig

The contract deployment config object.


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:

  • chainId:
    numberrequired
    - The chain ID where the contract is located.
  • erc721DeploymentConfig:
    DeploymentConfigrequired
    - The contract deployment config object.
  • wallet:
    HolographWalletrequired
    - The wallet that owns the contract and is going sign the bridge out payload message.

Returns:

Promise<0x${string}>

Example:

import { BridgeCollection } from "@holographxyz/sdk"

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

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

const bridgeOutPayload = await BridgeCollection.createInitCode(myContract.primaryChainId, erc721DeploymentConfig, wallet)

getInitCode()

Retrieve the initialization payload necessary for the bridgeOut function. This hexadecimal string encodes erc721DeploymentConfig, account, and the signature of the hashed version of the erc721DeploymentConfig.

Returns:

Promise<0x${string}>

Example:

 const bridgeOutPayload = await bridgeContract.getInitCode()

bridgeOut()

Makes the bridgeOut request.

Params:

  • destinationChainId:
    numberrequired
    - The chain ID of a network to which the contract is being bridged.

Returns:

Promise<Transaction>

Example:

  const tx = await bridgeContract.bridgeOut(destinationChainId)