@mirrorworld/library.assetminting.new
Version:
asset minting SDK
149 lines (99 loc) • 6.37 kB
Markdown
<h1><code>@mirrorworld/library.assetminting</code> Client SDK</h1>
This SDK contains the client side methods for the Asset Minting Solana Program
## Installation
> 🚨 Please make sure to add this NPM token in your `.npmrc` file:
> `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`
```bash
yarn add @mirrorworld/library.assetminting
```
# Usage
Import the `AssetMintingLib` instance into your client. It expects a `connection` and `wallet` instance. You can get
these
by using one of the Solana Wallet Adapters your application will use to connect to a Solana RPC.
These transactions require you to sign the transaction using your wallet. That means you need to have SOL. You can
request SOL from the [SolFaucet](https://solfaucet.com/)
```ts
import {
AssetMintingLib,
ASSET_MINTING_PROGRAM_ID
} from '@mirrorworld/library.assetminting';
const connection = useConnection()
/** Make sure your wallet is initialized and connected to the browser before providing to GameWalletLib */
const wallet = useWallet()
/** GameWalletLib instance */
const assetMintingLib = new AssetMintingLib(
ASSET_MINTING_PROGRAM_ID,
connection,
wallet
);
```
## Demo
Example:
You can see example project in this
repo [here](https://github.com/mirrorworld-universe/mirrorworld-program-library/blob/main/sdks/packages/asset-minting/examples/asset-minting-sdk-example/src/main.ts):
## Initialize Config Account
The Config Account PDA is the main part of the program which created from the name seed (the default seed define in the
SDK is "MirrorWorld"), in the config account we add the signing authority
```ts
let tx = await assetMintingLib.createInitializeConfigTransaction(signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey, NAME);
await assetMintingLib.addFeePayerAndRecentBlockHashInTransaction(tx, signingAuthorityWalletKeypair.publicKey);
assetMintingLib.signTransaction(tx, signingAuthorityWalletSecretKey);
let txHash = await connection.sendRawTransaction(tx.serialize());
console.log("Tx Hash: ", txHash);
```
See
example [here](https://github.com/mirrorworld-universe/mirrorworld-program-library/blob/main/sdks/packages/asset-minting/examples/asset-minting-sdk-example/src/main.ts#L85)
## Create Collection
The Create Collection is like helper method with help of this method we can create the collection and signing authority
as the update authority
```ts
let tx = await assetMintingLib.createCollectionTokenTransaction(collectionUuid, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
userWalletKeypair.publicKey, userWalletKeypair.publicKey, tokenName, tokenSymbol, tokenUrl, true, 0, creators, NAME,
SystemProgram.programId, SYSVAR_RENT_PUBKEY, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, mpl_programId);
// Adding Instructions for verifying the creators
await assetMintingLib.createAndAddCreatorSignMetadataInstruction(tx, collectionUuid, userWalletKeypair.publicKey, mpl_programId);
await assetMintingLib.addFeePayerAndRecentBlockHashInTransaction(tx, userWalletKeypair.publicKey);
assetMintingLib.signTransaction(tx, signingAuthorityWalletSecretKey);
assetMintingLib.signTransaction(tx, userWalletSecretKey);
let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);
```
See
example [here](https://github.com/mirrorworld-universe/mirrorworld-program-library/blob/main/sdks/packages/asset-minting/examples/asset-minting-sdk-example/src/main.ts#L101)
## Create Sub Collection
The Create Sub Collection is like helper method with help of this method we can create the Sub collection and signing
authority as the update authority
```ts
let tx = await assetMintingLib.createSubCollectionTokenTransaction(collectionUuid, subCollectionUuid, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
userWalletKeypair.publicKey, userWalletKeypair.publicKey, tokenName + "1", tokenSymbol, tokenUrl, true, 0, creators, NAME,
signingAuthorityWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, mpl_programId);
// Adding Instructions for verifying the creators
await assetMintingLib.createAndAddCreatorSignMetadataInstruction(tx, subCollectionUuid, userWalletKeypair.publicKey, mpl_programId);
await assetMintingLib.addFeePayerAndRecentBlockHashInTransaction(tx, userWalletKeypair.publicKey);
assetMintingLib.signTransaction(tx, signingAuthorityWalletSecretKey);
assetMintingLib.signTransaction(tx, userWalletSecretKey);
let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);
```
See
example [here](https://github.com/mirrorworld-universe/mirrorworld-program-library/blob/main/sdks/packages/asset-minting/examples/asset-minting-sdk-example/src/main.ts#L122)
## Create Asset
This method creates the asset and verify the collection
```ts
let tx = await assetMintingLib.createAssetTokenTransaction(assetUuid, subCollectionUuid, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
userWalletKeypair.publicKey, userWalletKeypair.publicKey, tokenName + "2", tokenSymbol, tokenUrl, true, 550, creators, NAME,
signingAuthorityWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, mpl_programId);
// Adding Instructions for verifying the creators
await assetMintingLib.createAndAddCreatorSignMetadataInstruction(tx, assetUuid, userWalletKeypair.publicKey, mpl_programId);
await assetMintingLib.addFeePayerAndRecentBlockHashInTransaction(tx, userWalletKeypair.publicKey);
assetMintingLib.signTransaction(tx, signingAuthorityWalletSecretKey);
assetMintingLib.signTransaction(tx, userWalletSecretKey);
let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);
```
See
example [here](https://github.com/mirrorworld-universe/mirrorworld-program-library/blob/main/sdks/packages/asset-minting/examples/asset-minting-sdk-example/src/main.ts#L142)
## Accounts
| Name | Description |
|:------------------------------:|:---------------------------------------------:|
| Config | Program config for the asset mint pda account |