You can interact with Metablocks protocol using `@kyraa/metablocks` package.
(For more details - please go through this - @kyraa/metablocks )
How to use @kyraa/metablocks package in your codebase ?
Install @kyraa/metablocks pacakge via your favourite node package manager. Here we use yarn to install @kyraa\metablocks
yarn add @kyraa/metablocks
Afterwards, to deposit into the Metablocks protocol you could do the following -
For interacting with any program in Solana blockchain, first we need a wallet and connection to the blockchain. Here is the sample code for establishing connection with Metablocks and solana network
const connection = new anchor.web3.Connection(CLUSTER_URL, 'confirmed');
const program = getMetaBlocksProgram(connection, wallet);
Universes allow you to use the protocol without caring about on-chain deployments. All you need is a wallet. You can create only one universe per wallet. For more info, refer the Official Docs
Below is a how you initialize/update an universe in your code.
Import Dependencies
import { createUniverse } from '@kyraa/metablocks';
To create an universe, all you need is below argument to be passed to the createUniverse method
const args = {
name: 'sample name',
description: ' sample description',
websiteUrl: 'http://your-sample.website.url',
connection: connection,
wallet: dummyWallet,
};
const tx = await createUniverse(args);
Import dependencies
import { updateUniverse } from '@kyraa/metablocks';
Similar to the above create universe, update universe is as simple as below updateUniverse call
const args = {
name: 'sample name',
description: ' sample description',
websiteUrl: 'http://your-sample.website.url',
connection: connection,
wallet: dummyWallet,
};
const tx = await updateUniverse(args);
Import dependencies
import { depositNft } from '@kyraa/metablocks';
Users can deposit their NFTs for upgrading their NFTs, it could be done with depositNft.
Once the user deposit's the NFT, in-return the User gets a receiptNFT as an acknowledgement for depositing the NFT.
A Meta NFT is generated. This NFT is the final combined NFT of the NFTs that you have deposited into the Metablocks program.
const args: GroupedDepositNftApiArgs = {
connection: connection,
isReceiptMasterEdition: false, // // You can mint a master-edition of the Receipt NFT, you can keep this a default
receiptUrl: 'http://localhost:8090', // reciept NFT url
receiptName: 'receiptName', // receipt NFT name
metaNftName: 'metaNftName', // Generated meta NFT name
metaNftUrl: 'http://localhost_meta_api.url', // this the url where combining of the deposited NFTs happen (Your rendering service URL)
isMetaNftMasterEdition: false, // You can mint a master-edition of the Meta NFT, you can keep this a default
wallet: dummyWallet,
mintKey: userNftMint, // this is the token mint of the User's NFT that needs to be deposited
universeKey: universeKey, // this is the public key where users wants to deposit the nft
};
await depositNft(args);
Import the API
import { depositNft } from '@kyraa/metablocks';
User could withdraw NFT anytime. The API to withdraw NFT is as simple as the following sample code.
const args: WithdrawNftApiArgs = {
connection: connection,
wallet: dummyWallet,
mintKey: userNftMint, // original mint public key of the user
universeKey: universeKey, // public key of the universe where the User deposited the NFT
};
await withdrawNft(args);
Import the API
import { depositNft } from '@kyraa/metablocks';
NFTs could also be withdraw from MetaBlocks Program using receiptMint Publickey
const args: WithdrawNftWithReceiptApiArgs = {
connection: connection,
receiptMint: pdaKeys.receiptMint, // public key of the receipt mint NFT
wallet: dummyWallet,
universeKey: universeKey, // public key of the universe where user deposited NFT
};
await withdrawNftWithReceipt(args);
