Skip to main content

HolographERC721Contract

The HolographERC721Contract class oversees holographable contracts, offering users the ability to effortlessly deploy contracts across multiple networks.

1. Constructor Parameters

createHolographERC721ContractInput

  • Type:
    CreateHolographERC721Contractrequired

Declare require contract parameters

type CreateHolographERC721Contract = {
primaryChainId: number;

contractInfo: {
name: string;
symbol: string;
royaltiesPercentage?: number;
salt?: string;
};
};
src/holograph/contract.ts
import { HolographERC721Contract } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

const myContract = new HolographERC721Contract({
primaryChainId: networks.polygon.chain,
contractInfo: {
name: "My First Contract",
symbol: "MFC",
royaltiesPercentage: 2000, // 20%
},
});
  • Validation:
    • primaryChainId:
      numberrequired
      - must be a valid chain ID.
    • contractInfo:
      • name:
        stringrequired
      • symbol:
        stringrequired
      • royaltiesPercentage:
        numberdefault: 0
        - must be a number between 0 and 10000.
      • salt:
        stringdefault: generateRandomSalt()
        - must be at least a 32-character hexadecimal string. The default is a random generated salt.

  • Setters:

    HolographERC721Contract has a couple of setters and they need to follow the above validation. Here's the full list:

    • setName()
    • setSymbol()
    • setRoyaltiesPercentage()
    • setSalt()

    ⚠️ The contract must be deployed before the setters can be evoked.


2. Properties

name

  • Type:
    string

The name of the contract.

symbol

  • Type:
    string

The symbol of the contract.

royaltiesPercentage

  • Type:
    number

The royalties percentage of the contract. It's a number between 0 and 10000.

salt

  • Type:
    0x${string}

The salt used to generate the contract's address.

account

  • Type:
    0x${string}

The account/signer who is interacting with the contract.

primaryChainId

  • Type:
    number

The chain ID of the first network where the contract will be deployed. This is the primary network of the contract.

chainIds

  • Type:
    number[]

The deployed chain IDs of the contract.

contractAddress

  • Type:
    0x${string}

The address that the contract was deployed to.

erc721ConfigHash

  • Type:
    0x${string}

The ERC721 config hash of the contract.

signature

  • Type:
    Signature

The signature of the last contract deployment.

txHash

  • Type:
    0x${string}

The transaction hash of the last deployment.


3. Methods

signDeploy()

Gets the signature data necessary for deploying an holographable contract.

Params:

  • holographWallet:
    HolographWalletrequired
  • chainId:
    numberdefault: {primaryChainId}
    - The chain ID of the network where the contract will be deployed. It defaults to the class's primaryChainId property.

Returns:

Promise<SignDeploy>

SignDeploy type reference:

import { HolographWallet } from "@holographxyz/sdk"

type SignDeploy = {
account: 0x${string}
config: DeploymentConfig
signature: Signature
chainId?: number
wallet?: { account: string | HolographWallet }
}

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

type Signature = {
r: 0x${string}
s: 0x${string}
v: 0x${string} | number
}

Example:

import { HolographWallet } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

import { defaultAccount } from "./config";

const wallet = new HolographWallet({
account: defaultAccount,
});

const signatureData = await myContract.signDeploy(wallet); // Primary chain ID.

// const signatureData = await myContract.signDeploy(wallet, networks.avalanche.chain); // Passing a different chain ID.

deploy()

Deploys an omnichain contract.

Params:

  • signatureData:
    SignDeployrequired
    - The signature data returned by the signDeploy() method.
  • options:
    WriteContractOptionsdefault: {}
    - The option overrides object for the transaction.

Returns:

Promise<{ contractAddress: 0x{string}, txHash: 0x{string} }>

import { HolographWallet } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

import { defaultAccount } from "./config";

const wallet = new HolographWallet({
account: defaultAccount,
});

const signatureData = await myContract.signDeploy(wallet); // Primary chain ID.

const { contractAddress, txHash } = await myContract.deploy(signatureData);

// Deploying to a different chain.
const binanceSmartChainSignatureData = await myContract.signDeploy(
wallet,
networks.chain.binanceSmartChain
);

await myContract.deploy(binanceSmartChainSignatureData);

How to override the default options:

const { contractAddress, txHash } = await myContract.deploy(signatureData, {
gasLimit: BigInt(1000000),
gasPrice: BigInt(1000000000),
});

Here's the full list of override options:

  • accessList
  • account
  • chain
  • dataSuffix
  • gas
  • gasPrice
  • maxFeePerBlobGas
  • maxFeePerGas
  • maxPriorityFeePerGas
  • nonce
  • type
  • value

hydrate()
static

Hydrates the contract from a previous deployment.

Params:

  • hydrateContract:
    HydrateHolographERC721Contractrequired
    - The configuration object for hydrating the contract. See below for the type reference.

Returns:

HolographERC721Contract
- The hydrated contract class instance, ready for use.

HydrateHolographERC721Contract type reference:

type HydrateHolographERC721Contract = {
contractInfo: {
name: string;
symbol: string;
royaltiesPercentage?: number;
salt?: string;
}
chainId: number;
address: Address;
txHash?: 0x${string};
}

Example:

import { HolographERC721Contract } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

const myContract = await HolographERC721Contract.hydrate({
chainId: networks.polygon.chain,
address: "0xaaaB48817189C5768887Ed7809ebF6E88e629bD5",
contractInfo: {
name: "My First Contract",
symbol: "MFC",
},
});

console.log(myContract.name); // My First Contract
console.log(myContract.symbol); // MFC
console.log(myContract.contractAddress); // 0xaaaB48817189C5768887Ed7809ebF6E88e629bD5
console.log(myContract.chainIds); // [137]

createErc721DeploymentConfig()

Creates the ERC721 deployment config. This method is useful for bridging the contracts and its NFTs to other networks. For more info, check out the BridgeNFT class reference.

Params:

  • account:
    0x${string}required
    - The signer account address.
  • chainId:
    numberdefault: {primaryChainId}
    - The chain ID of the network where the contract will be deployed. It defaults to the class's primaryChainId property.

Returns:

import { networks } from "@holographxyz/networks";

import { defaultAccount } from "./config";

const erc721Config = await myContract.createErc721DeploymentConfig(
defaultAccount.address,
networks.avalanche.chain
);

getContractInfo()

Retrieves contract information, essentially the initial data passed to the constructor, along with any potential modifications made by the setters, prior to deployment.

Returns:

ContractInfo

ContractInfo type reference:

type ContractInfo = {
name: string;
symbol: string;
royaltiesPercentage: number;
salt: `0x${string}`;
};

Example:

const contractInfo = await myContract.getContractInfo();

console.log(contractInfo.name); // My First Contract.

4. Retrieving Contract Data

You can retrieve data from a deployed contract and deploy it to another network using the following approach:

src/holograph/contract.ts
import { ContractType, HolographProtocol } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

import { wallet } from "./config";

const protocol = new HolographProtocol();

// HolographERC721Contract instance.
const contract = await protocol.hydrateContractFromAddress({
address: "0xaaaB48817189C5768887Ed7809ebF6E88e629cf8",
chainId: networks.polygon.chain,
type: ContractType.CxipERC721,
});

// Deploying to a different chain.
const signatureData = await contract.signDeploy(
wallet,
networks.avalanche.chain
);

await contract.deploy(signatureData);