BridgeContract
The BridgeContract class facilitates the bridging of holographic contract across different chains.
To bridge any holographic contract to another network, a three-step process is followed:
- Bridge Out - Users initiate a bridge out request to the
HolographBridge
contract on the source chain. - Message Layer - The message layer is responsible for transmitting the message from the source chain to the destination chain.
- 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
bridgeContractInput
- Type:BridgeContractInputrequired
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 BridgeContractInput = {
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.
- sourceChainId:
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:
import { BridgeContract } from "@holographxyz/sdk"
import { wallet } from "./config"
import { myContract } from "./contract"
const erc721DeploymentConfig = myContract.createErc721DeploymentConfig(
wallet.account.address
)
const bridgeContract = new BridgeContract(
{
sourceChainId: myContract.primaryChainId,
contractAddress: myContract.contractAddress,
erc721DeploymentConfig,
wallet,
},
{
gasPrice: BigInt(132000000000),
gasLimit: BigInt(650000),
}
)
For further details on contract 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 envoked 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:
Example:
import { BridgeContract } from "@holographxyz/sdk"
import { wallet } from "./config"
import { myContract } from "./deploy"
const erc721DeploymentConfig = myContract.createErc721DeploymentConfig(
wallet.account.address
)
const bridgeOutPayload = await BridgeContract.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:
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:
Example:
const tx = await bridgeContract.bridgeOut(destinationChainId)