Holographic Asset SDK
Overview
Coming in 2024: The Holographic Asset SDK enables holographic assets to be created, deployed, minted, and bridged. Holographic assets are fungible and non-fungible tokens that exist natively on any public or private blockchain.
Functions
- Create: Establish new holographic assets with defined attributes and functionalities.
- Deploy: Position the newly created holographic assets on the desired blockchain.
- Mint: Issue new holographic assets, expanding their presence and utilization.
- Bridge: Move holographic assets between supported EVM blockchains.
Example
The following section includes the Holograph Factory contract with a simple Javascript example that demonstrates how to deploy a holographic contract.
HolographFactory
import { ethers } from 'ethers';
interface DeploymentConfig {
contractType: string;
chainType: string;
salt: string;
byteCode: string;
initCode: string;
}
interface Verification {
r: string;
s: string;
v: number;
}
interface BridgeSettings {
toChain: number;
value: number;
gasLimit: number;
gasPrice: number;
}
// HolographFactory class encapsulating the smart contract functionalities
class HolographFactory {
private contract: ethers.Contract;
constructor(provider: ethers.providers.Provider, signer: ethers.Signer, contractAddress: string) {
const abi = [ /* ABI of the HolographFactory */ ];
this.contract = new ethers.Contract(contractAddress, abi, signer);
}
// init function
async init(initPayload: string): Promise<string> {
const result = await this.contract.init(initPayload);
return result;
}
// bridgeIn function
async bridgeIn(fromChain: number, payload: string): Promise<string> {
const result = await this.contract.bridgeIn(fromChain, payload);
return result;
}
// bridgeOut function
async bridgeOut(toChain: number, sender: string, payload: string): Promise<{ selector: string, data: string }> {
const result = await this.contract.bridgeOut(toChain, sender, payload);
return result;
}
// deployHolographableContractMultiChain function
async deployHolographableContractMultiChain(
config: DeploymentConfig,
signature: Verification,
signer: string,
deployOnCurrentChain: boolean,
bridgeSettings: BridgeSettings[]
): Promise<void> {
await this.contract.deployHolographableContractMultiChain(config, signature, signer, deployOnCurrentChain, bridgeSettings);
}
// deployHolographableContract function
async deployHolographableContract(
config: DeploymentConfig,
signature: Verification,
signer: string
): Promise<void> {
await this.contract.deployHolographableContract(config, signature, signer);
}
// getHolograph function
async getHolograph(): Promise<string> {
const holographAddress = await this.contract.getHolograph();
return holographAddress;
}
// setHolograph function
async setHolograph(holograph: string): Promise<void> {
await this.contract.setHolograph(holograph);
}
// getRegistry function
async getRegistry(): Promise<string> {
const registryAddress = await this.contract.getRegistry();
return registryAddress;
}
// setRegistry function
async setRegistry(registry: string): Promise<void> {
await this.contract.setRegistry(registry);
}
}
// Usage:
// const provider = new ethers.providers.JsonRpcProvider();
// const signer = provider.getSigner();
// const holographFactory = new HolographFactory(provider, signer, 'YOUR_HOLOGRAPHBRIDGE_CONTRACT_ADDRESS');
HolographBridge
Here is an example of how to bridge a holographic asset between blockchains.
import { ethers, Signer } from 'ethers';
const HolographBridgeABI = [
/* ABI of the HolographBridge */
];
class HolographBridge {
private contract: ethers.Contract;
constructor(private signer: Signer, contractAddress: string) {
this.contract = new ethers.Contract(contractAddress, HolographBridgeABI, signer);
}
async init(initPayload: string): Promise<string> {
const txResponse = await this.contract.init(initPayload);
await txResponse.wait();
return txResponse.hash;
}
async bridgeInRequest(
nonce: number,
fromChain: number,
holographableContract: string,
hToken: string,
hTokenRecipient: string,
hTokenValue: ethers.BigNumber,
doNotRevert: boolean,
bridgeInPayload: string
): Promise<string> {
const txResponse = await this.contract.bridgeInRequest(
nonce,
fromChain,
holographableContract,
hToken,
hTokenRecipient,
hTokenValue,
doNotRevert,
ethers.utils.arrayify(bridgeInPayload)
);
await txResponse.wait();
return txResponse.hash;
}
async bridgeOutRequest(
toChain: number,
holographableContract: string,
gasLimit: ethers.BigNumber,
gasPrice: ethers.BigNumber,
bridgeOutPayload: string
): Promise<string> {
const txResponse = await this.contract.bridgeOutRequest(
toChain,
holographableContract,
gasLimit,
gasPrice,
ethers.utils.arrayify(bridgeOutPayload)
);
await txResponse.wait();
return txResponse.hash;
}
async getBridgeOutRequestPayload(
toChain: number,
holographableContract: string,
gasLimit: ethers.BigNumber,
gasPrice: ethers.BigNumber,
bridgeOutPayload: string
): Promise<string> {
const samplePayload = await this.contract.getBridgeOutRequestPayload(
toChain,
holographableContract,
gasLimit,
gasPrice,
ethers.utils.arrayify(bridgeOutPayload)
);
return ethers.utils.hexlify(samplePayload);
}
async getMessageFee(
toChain: number,
gasLimit: ethers.BigNumber,
gasPrice: ethers.BigNumber,
crossChainPayload: string
): Promise<{ hlgFee: ethers.BigNumber; msgFee: ethers.BigNumber; dstGasPrice: ethers.BigNumber }> {
const [hlgFee, msgFee, dstGasPrice] = await this.contract.getMessageFee(
toChain,
gasLimit,
gasPrice,
ethers.utils.arrayify(crossChainPayload)
);
return {
hlgFee: ethers.BigNumber.from(hlgFee),
msgFee: ethers.BigNumber.from(msgFee),
dstGasPrice: ethers.BigNumber.from(dstGasPrice)
};
}
}
// Usage:
async function main() {
// Connect to the Ethereum network
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
// Create an instance of the HolographBridge class
const holographBridge = new HolographBridge(signer, 'YOUR_HOLOGRAPHBRIDGE_CONTRACT_ADDRESS');
// Call the init method
const initPayload = '0x...'; // ABI encoded initialization payload
const initTxHash = await holographBridge.init(initPayload);
console.log('Init transaction sent with hash:', initTxHash);
// Call the bridgeInRequest method
const bridgeInTxHash = await holographBridge.bridgeInRequest(
0, // nonce
1, // fromChain
'0x...', // holographableContract
'0x...', // hToken
'0x...', // hTokenRecipient
ethers.BigNumber.from('1000000000000000000'), // hTokenValue (1 ether)
false, // doNotRevert
'0x...' // bridgeInPayload
);
console.log('BridgeInRequest transaction sent with hash:', bridgeInTxHash);
}
main().catch(console.error);
// Define your parameters
const toChain = 1; // Destination chain ID
const holographableContract = 'YOUR_HOLOGRAPHBRIDGE_CONTRACT_ADDRESS';
const gasLimit = ethers.BigNumber.from(1000000);
const gasPrice = ethers.BigNumber.from(1000000000); // 1 gwei
const bridgeOutPayload = '0x123456...'; // ABI-encoded payload
// Usage of bridgeOutRequest
async function executeBridgeOutRequest() {
try {
const txHash = await holographBridge.bridgeOutRequest(toChain, holographableContract, gasLimit, gasPrice, bridgeOutPayload);
console.log('Transaction hash:', txHash);
} catch (error) {
console.error('Error executing bridgeOutRequest:', error);
}
}
// Usage of getBridgeOutRequestPayload
async function fetchBridgeOutRequestPayload() {
try {
const samplePayload = await holographBridge.getBridgeOutRequestPayload(toChain, holographableContract, gasLimit, gasPrice, bridgeOutPayload);
console.log('Sample payload:', samplePayload);
} catch (error) {
console.error('Error fetching bridgeOutRequestPayload:', error);
}
}
// Usage of getMessageFee
async function fetchMessageFee() {
try {
const crossChainPayload = '0xabcdef...'; // Your cross-chain payload
const fees = await holographBridge.getMessageFee(toChain, gasLimit, gasPrice, crossChainPayload);
console.log('Fees:', fees);
} catch (error) {
console.error('Error fetching message fee:', error);
}
}
// Execute the functions
executeBridgeOutRequest();
fetchBridgeOutRequestPayload();
fetchMessageFee();