Mint ERC721 Assets
- Learn how to mint an ERC721 Assets on Myria.
- To inspect the function in the SDK with details payload and response format you can reference at SDK Docs.
For Minting ERC721 assets with >10 assets per request, please use Mint Queue ERC721
Prerequisites
1. Technical requirements:
2. Business criteria:
- Create project through Myria TS SDK or Developer Portal
- Created collection through Myria TS SDK or Developer Portal
Minting Multiple Assets
Implementation
You can create a new ERC721 mint transaction as follows:
Open a Typescript project created here
Create the
create-bulk-erc721-mint-transaction.ts
file in the above project and paste this code:
- Typescript
import { MintingManager, MintERC721Params, MintERC721Response, FeeType, EnvTypes } from "myria-core-sdk";
(async (): Promise<void> => {
// define the environment: STAGING or PRODUCTION
const env = EnvTypes.PRODUCTION;
// get access to the `MintingManager`
const mintingManager: MintingManager = new MintingManager(env);
const feePercentage = 8; // Integer percentage of fee
const startTokenId = 1; // The begin token to start the minting
const endTokenId = 10000; // The end token
const batchSize = 100;
const starkKey = 'YOUR_STARK_KEY';
const walletAddress = 'YOUR_WALLET_ADDRESS';
const baseUrl = 'YOUR_METADATA_URL';
const smartContractAddress = 'SMART_CONTRACT_ADDRESS';
for (let i = startTokenId; i <= endTokenId; i += batchSize) {
let assetsToMint: MintAssetErc721Info[] = [];
for (let id = i; id < i + batchSize && id <= endTokenId; id++) {
const asset: MintAssetErc721Info = {
uri: `${baseUrl}/${id}`,
tokenId: String(id),
description: "",
fees: [
{
percentage: feePercentage,
receiptAddress: walletAddress,
feeType: FeeType.ROYALTY
},
],
};
assetsToMint.push(asset);
}
const params: BulkMintERC721Params = {
starkKey: starkKey,
contractAddress: smartContractAddress,
assets: assetsToMint,
isSupportGetBulkMetadata: false,
fees: [
{
percentage: feePercentage,
receiptAddress: walletAddress,
feeType: FeeType.ROYALTY
},
],
};
try {
// create a bulk mint transaction
const mintResult = await mintingManager.bulkMintNfts(params);
console.log("Bulk minting is completed. Result: ", mintResult);
} catch (error) {
console.error("Bulk minting failed with error: ", error);
}
// sleep for 4-5 seconds
await new Promise(resolve => setTimeout(resolve, 4000 + Math.random() * 1000));
}
})();
Replace the params
object values as follows:
STARK_KEY
- Stark Key, has to start with0x
CONTRACT_ADDRESS
- contract address used to withdraw assets to the Ethereum networkTOKEN_URI
- URL path to the mintable asset metadataTOKEN_ID
- unique identifier of a given asset, should be an incremental numeric value starting from 1DESCRIPTION
- description of a given assetROYALTY_PERCENTAGE
- royalty percentage a wallet would receive from secondary salesROYALTY_RECIPIENT_ADDRESS
- wallet address of royalty recipientIS_SUPPORT_GET_BULK_METADATA
- This field is default set to false, only enable it to true if your metadata URL have support to get the batch metadata as this format:metadataUrl?tokenIds=1,2,3,4,5,6....
- Add a script to load the
create-bulk-erc721-mint-transaction-v2.ts
file inpackage.json
:
{
"scripts": {
"create-project": "ts-node create-project.ts",
"create-collection": "ts-node create-collection.ts",
"create-bulk-erc721-mint-transaction-v2": "ts-node create-bulk-erc721-mint-transaction-v2.ts" },
}
- Run the
create-bulk-erc721-mint-transaction
script:
npm run create-erc721-mint-transaction
After a mint transaction is created, you will see the response that looks as follows: BulkMintERC721ResponseData
Single Mint Asset
- The single mint execute the NFT minting for 1 asset per request. It is used for testing purpose in case if you'd to try the minting testing with low range number of assets.
- For production minting with large number of assets, it is recommend you can use the Minting Multiple Assets in the section below.
Implementation
You can find the full implementation of this code sample in the myria-ts-samples repository.
You can create a new ERC721 mint transaction as follows:
- Create the
create-erc721-mint-transaction.ts
file in the above project and paste this code:
- Single-Mint-Erc721
import {
MintingManager,
MintERC721Params,
MintERC721Response,
FeeType
} from "myria-core-sdk";
import config from "../config";
(async (): Promise<void> => {
const env = config.environment;
const mintingManager: MintingManager = new MintingManager(env);
const feePercentage = 3; // Must be integer number to indicate the percentage of royaltee fee
const starkKey: string = config.stark_key;
const contractAddress: string = config.collection_contract_address;
const tokenUri: string = config.token_uri; // Based metadata URL in the collection
const tokenId: string = config.token_id; // Token ID specific for the NFT that intend to mint
const royaltyRecipient: string = config.public_key; // Royalty destination wallet address
const params: MintERC721Params = {
starkKey: starkKey,
contractAddress: contractAddress,
uri: tokenUri,
tokenId: tokenId,
description: "sample description",
fees: [
{
percentage: feePercentage,
receiptAddress: royaltyRecipient,
feeType: FeeType.ROYALTY
},
],
requestId: "random-uuid",
partnerRefId: "project-id",
requestDescription: "request-description"
};
console.log("Initiating a mint transaction...");
const mintTransactionResponse: MintERC721Response = await mintingManager.createMintTransactionERC721(
params
);
console.log("Mint transaction response:");
console.log(JSON.stringify(mintTransactionResponse, null, 2));
})();
Replace the params
object values as follows:
STARK_KEY
- Stark Key, has to start with0x
CONTRACT_ADDRESS
- contract address used to withdraw assets to the Ethereum networkTOKEN_URI
- URL path to the mintable asset metadataTOKEN_ID
- unique identifier of a given asset, should be an incremental numeric value starting from 1DESCRIPTION
- description of a given assetROYALTY_PERCENTAGE
- royalty percentage a wallet would receive from secondary salesROYALTY_RECIPIENT_ADDRESS
- wallet address of royalty recipientREQUEST_ID
- The unique request ID (can use random UUID generated) - using for tracking minting statusPARTNER_REF_ID
- The project ID created in Myria - using for identify the partner and project that you are interact with.REQUEST_DESCRIPTION
- The description of request if you'd to keep track something important or describe from your end
- Use a pure integer number in the
ROYALTY_PERCENTAGE
. SettingROYALTY_PERCENTAGE
to 3 means the royalty paid out will be 3% of the sale price. - The default value for the
ROYALTY_RECIPIENT_ADDRESS
is the collection creator address.
Make sure there is no trailing /
at the end of the TOKEN_URI
or you won't be able to mint assets.
- Add a script to load the
create-erc721-mint-transaction.ts
file inpackage.json
:
{
"scripts": {
"create-project": "ts-node create-project.ts",
"create-collection": "ts-node create-collection.ts",
"create-erc721-mint-transaction": "ts-node create-erc721-mint-transaction.ts"
},
}
- Run the
create-erc721-mint-transaction
script:
npm run create-erc721-mint-transaction
Or if you're using yarn:
yarn create-erc721-mint-transaction
After a mint transaction is created, you will see the response that looks as follows:
MintERC721Response
{
"asset": {
"uri": "https://gateway.pinata.cloud/ipfs/QmSjWbBS3rPu5K2TnhyXmwGE1GcVZMRFKg5K3iMLGca1m8/1",
"starkKey": "0x7fe1b18d74145afd74c0b84b693c9e8eb4de49a3972743f4cd2fbfc3904e9cb",
"assetType": "MINTABLE_ERC721",
"tokenId": "1",
"tokenAddress": "0x3bb911f179f34aac30ef4e175f57dedf49312cb7",
"status": "MINTED",
"description": "Asset X",
"collectionId": 39,
"creatorStarkKey": "0x7fe1b18d74145afd74c0b84b693c9e8eb4de49a3972743f4cd2fbfc3904e9cb",
"updatedAt": "2022-08-17T04:11:27.763Z",
"name": "mto1",
"imageUrl": null,
"animationUrl": null,
"animationUrlMimeType": null,
"assetMintId": "0x400d7f08c2bd93fded45000d55f20a1eb52a8d90c6912a1315533179219937c",
"transactionId": 39026,
"id": 26149,
"createdAt": "2022-08-17T04:11:26.013Z",
"metadata": {},
"metadataOptional": {
"description": "MT Original 1",
"externalUrl": "",
"image": "https://gateway.pinata.cloud/ipfs/Qmae3dbyXos21g7oSeK3g4C7GyhSV8pxXrkWFmekgaMLPt",
"attributes": [
{
"trait_type": "Category",
"value": "Silver"
},
{
"trait_type": "Edition",
"value": 1
},
{
"trait_type": "Level",
"value": 1
}
]
},
"publicId": "74eab8f4-b68d-410c-a8f6-513a05b2d135"
},
"transaction": {
"tokenType": "MINTABLE_ERC721",
"vaultId": 54424,
"quantizedAmount": "1",
"starkKey": "0x7fe1b18d74145afd74c0b84b693c9e8eb4de49a3972743f4cd2fbfc3904e9cb",
"transactionCategory": "MintRequest#0x3bb911f179f34aac30ef4e175f57dedf49312cb7#1",
"transactionId": 39026,
"transactionType": "MintRequest",
"transactionStatus": "Prepare",
"createdAt": 1660709487350,
"tokenAddress": "0x3bb911f179f34aac30ef4e175f57dedf49312cb7",
"assetType": "0x23d90e1e5140402f246c683dcd6c3d6876968ff03c0187eddc9c255b3a0f4c5",
"assetId": "0x400d7f08c2bd93fded45000d55f20a1eb52a8d90c6912a1315533179219937c",
"tokenId": "1",
"quantum": "1",
"blueprint": "https://gateway.pinata.cloud/ipfs/QmSjWbBS3rPu5K2TnhyXmwGE1GcVZMRFKg5K3iMLGca1m8/1",
"nonce": 1,
"environment": "staging"
}
}
Please note that you are recommended to inform Myria's team after the minting is completed in Staging/Production. Myria will help to refresh fully your collection metadata to have the ability for filtering and query the NFTs/assets based on attributes.
Royalties
Note that the royalties fields is an optional params and you only need to specify it once having plan for percentage of fee in the Royalty in every trading transactions.
For more details, you can reference on the SDK DOCS.
Next steps
Now that you minted your first ERC721 asset, you can list it on the Myria NFT Marketplace.