Collection - SDK
Learn how to create a Myria collection.
Please note, in the Staging environment you can create five collections and 50,000 mint transactions per collection per month.
If you want to create collections for your project in the Production environment, or you need to increase those limits, please contact our team.
Be sure to include your project id in the request message.
Prerequisites
- Basic Javascript and Typescript knowledge
- Web IDE such as VS Code
- Latest NodeJs
- Web3 wallet address and Stark Key
- Typescript project created here or a new one with similar structure
- Registered Myria developer account and project
3. Create a Collection with SDK
You can find the full implementation of this code sample in the myria-ts-samples repository.
You can create a new Myria collection as follows:
Open a Typescript project created here
Create the
create-collection.tsfile in the above project and paste this code:
- Typescript
import { CollectionManager, CreateCollectionByApiKeyParams, CreateCollectionResponse, EnvTypes } from "myria-core-sdk";
(async (): Promise<void> => {
// define the environment: STAGING or PRODUCTION
const env = EnvTypes.STAGING;
// get access to the `CollectionManager`
const collectionManager: CollectionManager = new CollectionManager(env);
// Defined params
const params: CreateCollectionByApiKeyParams = {
name: name_Collection;
collectionImageUrl?: 'abc.png';
description?: description;
iconUrl?: abc.png;
contractAddress: contractAddress; // Smnart contract address
ownerPublicKey: Owner PublicKey;
metadataApiUrl: metaDataApiURL; // Base metadata url to point to off-chain data of collection
projectId: 1;
accountId: accountId; // Unique account ID
apiKey: APIKey // Generated API key
};
// Created collection
console.log("Create the Collection...");
const newCollectionResponse: CreateCollectionResponse = await collectionManager.createCollectionByApiKey(params);
console.log("Created Collection response:");
console.log(JSON.stringify(newCollectionResponse, null, 2));
// log the result
console.log(JSON.stringify(collectionResponse, null, 2));
})();
Replace the params values as follows:
COLLECTION_NAME- collection nameCOLLECTION_DESCRIPTION- collection descriptionCONTRACT_ADDRESS- contract address used to withdraw assets to the Ethereum networkMETADATA_API_URL- API URL that will store collection metadataPROJECT_ID- project id to which the collection will belongAPI_KEY- Api Key, retrieve the developer API Key in the [Developer Portal Setting Page].MYRIA_USER_ID- Myria User ID, retrieve the myria user ID in the [Developer Portal Setting Page]
- Add a script to load the
create-collection.tsfile inpackage.json:
{
"scripts": {
"create-project": "ts-node create-project.ts",
"create-collection": "ts-node create-collection.ts",
},
}
- Run the
create-collectionscript:
npm run create-collection
After a collection is created, you will see the response that looks as follows:
CreateCollectionResponse
{
"id": 19,
"createdAt": "2022-07-12T10:10:22.192Z",
"updatedAt": "2022-07-12T10:10:22.192Z",
"name": "MT Collection",
"collectionImageUrl": null,
"description": "MT original",
"iconUrl": null,
"contractAddress": "0x365bdeE115b3Ad192a494FDa6a4d18E79fdf03Af",
"ownerPublicKey": "0x75e0D99fa416823F4C07CDafC86A3B0cA37B52A5",
"metadataApiUrl": "https://gateway.pinata.cloud/ipfs/QmSjWbBS3rPu5K2TnhyXmwGE1GcVZMRFKg5K3iMLGca1m8",
"starkKey": "0x43be26f8a75d1fc532a871ed88561f75fadd1a901b4fed01d0c8ef48762f1a9",
"publicId": "24dd6da6-e129-4e4f-ab01-a4408649f3bd",
"isHot": false,
"metadataSchema": [],
"project": {
"id": 33,
"createdAt": "2022-07-07T11:28:14.731Z",
"updatedAt": "2022-07-12T10:10:22.213Z",
"name": "Test Game",
"companyName": "Gaming Studio X",
"contactEmail": "test@google.com",
"collectionLimitExpiresAt": "2022-08-08T15:07:01.266Z",
"collectionMonthlyLimit": 5,
"collectionRemaining": 3,
"mintLimitExpiresAt": null,
"mintMonthlyLimit": 50000,
"mintRemaining": 50000,
"publicId": "3a81b6f4-821e-48ae-bcd5-0d99533c9136",
"__entity": "ProjectEntity"
},
"__entity": "CollectionEntity"
}
4. Create a Collection Metadata Schema
This is a mandatory step before you can start the minting process. If you don't add a metadata schema for your collection, you won't see your assets' attributes and filtering options on the Myria Marketplace.
You can create a metadata schema for your collection as follows:
Open a Typescript project created above.
Create the
create-metadata-schema.tsfile and paste this code:
- Typescript
import { CollectionManager, EnvTypes, CreateCollectionMetadataParams, CollectionDetailsResponseData, Metadata } from "myria-core-sdk";
(async (): Promise<void> => {
// define the environment: STAGING or PRODUCTION
const env = EnvTypes.STAGING;
// get access to the `CollectionManager`
const collectionManager: CollectionManager = new CollectionManager(env);
// define collection contract address and stark key
const contractAddress: string = "CONTRACT_ADDRESS";
const starkKey: string = "STARK_KEY";
// define the metadata schema
const metadataSchema: Metadata[] = [
{
name: "ATTRIBUTE_NAME_1",
type: "enum",
filterable: true
},
{
name: "ATTRIBUTE_NAME_N",
type: "enum",
filterable: false
}
];
// define params
const params: CreateCollectionMetadataParams = {
metadata: metadataSchema,
starkKey: starkKey
};
// create a schema
const response: CollectionDetailsResponseData = await collectionManager.createCollectionMetadataByAddress(contractAddress, params);
})();
Replace the contractAddress and starkKey values as follows:
CONTRACT_ADDRESS- contract address used to withdraw assets to the Ethereum networkSTARK_KEY- Stark Key, has to start with0x
Each metadata schema object has three properties:
name- the name of the metadata schema attribute. Should matchtrait_typein the Opensea metadata schema.type- the type of the metadata schema attribute. Acceptsenum,string, andnumber. In most cases, you should useenum.filterable- the flag that defines if the attribute should be filterable on the Myria marketplace. Acceptstrueorfalse.
- Add a script to load the
create-metadata-schema.tsfile inpackage.json:
{
"scripts": {
"create-project": "ts-node create-project.ts",
"create-collection": "ts-node create-collection.ts",
"create-metadata-schema": "ts-node create-metadata-schema.ts"
},
}
- Run the
create-metadata-schemascript:
npm run create-metadata-schema
After a metadata schema is created, you will see the response that looks as follows:
CollectionDetailsResponseData
{
"status": "success",
"data": {
"id": 129,
"name": "Buidlers v3",
"collectionImageUrl": null,
"description": "A third iteration of Buidlers collection",
"iconUrl": null,
"contractAddress": "0x615876a6978986e1fe3ef9e8404ae41e61196c62",
"ownerPublicKey": "0x7b08c88a6d0f27620798b57f3d744c62b0dea634",
"metadataApiUrl": "https://gateway.pinata.cloud/ipfs/QmXe7YfTbd5fWh1F7eNXvGNgxaASDb6fKikrZBLCgxYW4v",
"starkKey": "0x7d682c993fa1090bf7cdc9598bf7e0062b1d0308c90e1fafca44d867cdf05f4",
"publicId": "d300e048-fd74-4c1c-b967-35ed0982e0f3",
"isHot": false,
"metadataSchema": [
{
"name": "Race",
"type": "enum",
"filterable": true
},
{
"name": "Power",
"type": "enum",
"filterable": true
}
],
"createdAt": "2022-10-05T10:55:28.253Z",
"updatedAt": "2022-10-06T03:29:52.757Z",
"project": {
"id": 120,
"name": "Solid project",
"companyName": "Solid company",
"contactEmail": "solid@gmail.com",
"publicId": "69a7f268-4f9b-4f3f-b46a-b8830a589399"
},
"totalAssets": 8,
"totalAssetsForSale": 8
}
}