HolographLegacyCollection
The HolographLegacyCollection class oversees holographable contracts, offering users the ability to effortlessly deploy contracts across multiple networks.
1. Constructor Parameters
holographConfig
- Type:HolographConfigrequired
The HolographConfig object the class will use to deploy contracts.
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,
},
};
createLegacyCollectionInput
- Type:CreateLegacyCollectionrequired
Declare require contract parameters
enum TokenType {
ERC721 = "ERC721",
ERC1155 = "ERC1155",
}
type CreateLegacyCollection = {
primaryChainId: number;
collectionInfo: {
name: string;
symbol: string;
description?: string;
tokenType?: TokenType;
royaltiesBps?: number;
salt?: string;
};
};
import { HolographLegacyCollection } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";
import { holographConfig } from "./config";
const myContract = new HolographLegacyCollection(holographConfig, {
primaryChainId: networks.polygon.chain,
collectionInfo: {
name: "My First Collection",
symbol: "MFC",
description: "Probably nothing.",
royaltiesBps: 2000, // 20%
salt: "0x0000000000000000000000000000000000000000000000000000018e7cc167e2",
},
});
- Validation:
- primaryChainId: numberrequired- must be a valid chain ID.
- collectionInfo:
- name: stringrequired
- symbol: stringrequired
- description: stringdefault: ""
- tokenType: ERC721 | ERC1155default: ERC721
- royaltiesBps: 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.
- name:
- primaryChainId:
-
Setters:
HolographLegacyCollection
has a couple of setters and they need to follow the above validation. Here's the full list:- setName()
- setDescription()
- setSymbol()
- setTokenType()
- setRoyaltiesBps()
- setSalt()
⚠️ The contract must be deployed before the setters can be evoked.
2. Properties
name
- Type: string
The name of the contract.
description
- Type: string
The description of the contract.
symbol
- Type: string
The symbol of the contract.
tokenType
- Type: TokenType
The type of token that the contract will deploy.
royaltiesBps
- 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.
collectionAddress
- 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:
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, holographConfig } from "./config";
const wallet = new HolographWallet({
account: defaultAccount,
chainsRpc: holographConfig.networks,
});
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:
import { HolographWallet } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";
import { defaultAccount, holographConfig } from "./config";
const wallet = new HolographWallet({
account: defaultAccount,
chainsRpc: holographConfig.networks,
});
const signatureData = await myContract.signDeploy(wallet); // Primary chain ID.
const { collectionAddress, 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 { collectionAddress, 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
hydrateFrom() static
Hydrates the contract from a previous deployment.
Params:
- hydrateCollectionConfig:HydrateCollectionConfigrequired- The configuration object for hydrating the contract. See below for the type reference.
Returns:
HydrateCollectionConfig type reference:
import { HolographConfig } from "@holographxyz/sdk";
type HydrateCollectionConfig = {
chainId: number;
collectionAddress: 0x${string};
holographConfig: HolographConfig;
}
Example:
import { HolographLegacyCollection } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";
import { holographConfig } from "./config";
const myContract = await HolographLegacyCollection.hydrateFrom({
chainId: networks.polygon.chain,
collectionAddress: "0xaaaB48817189C5768887Ed7809ebF6E88e629bD5",
holographConfig,
});
console.log(myContract.name); // My First Collection
console.log(myContract.symbol); // MFC
console.log(myContract.collectionAddress); // 0xaaaB48817189C5768887Ed7809ebF6E88e629bD5
console.log(myContract.chainIds); // [137, 56]
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
);
getCollectionInfo()
Retrieves contract information, essentially the initial data passed to the constructor, along with any potential modifications made by the setters, prior to deployment.
Returns:
CollectionInfo type reference:
type CollectionInfo = {
name: string;
symbol: string;
royaltiesBps: number;
salt: `0x${string}`;
tokenType: TokenType;
description?: string;
};
Example:
const collectionInfo = await myContract.getCollectionInfo();
console.log(collectionInfo.name); // My First Contract