Skip to main content

Myria Core SDK Overview

The myria-core-sdk represents a Typescript SDK that allows interacting with Myria components.

Installation

You can install the Myria Core SDK as follows:

npm i myria-core-sdk

Modules

Myria Core SDK consists of several modules:

  1. Developer Accounts. Represent developer identities on Myria. Registered accounts can create projects and manage assets on the Myria chain.
  2. Projects. Represent games, creative or entertainment products. Having a project is required to work with Myria components described below.
  3. Collections. Represent digital assets in a set of related items: characters, cosmetics, land, etc. Developer accounts can create multiple collections that belong to a given project.
  4. Minting. Represent mint transactions that issue assets on Myria. The current implementation supports assets based on ERC721 standard. However, the upcoming versions will include the ERC20 tokens too.
  5. Onchain Assets. Represent unique pieces of immutable intellectual property that have distinct value: in-game items, digital art, tickets, etc. Those are commonly referred to as non-fungible tokens or NFTs.

Authentication

Many SDK functions rely on a Web3 public key and the corresponding Stark Key to perform operations that require authentication and transaction signatures. You can generate those keys using the Myria quickstart.

Samples

You can find code samples for the Myria Core SDK on GitHub:

Environments

Myria Core SDK supports two environments:

  • STAGING for testing purposes
  • PRODUCTION for production

You have to configure the environment before instantiating any myria-core-sdk manager (ProjectManager, CollectionManager, MintingManager, etc). You can configure the environment as follows:

import { EnvTypes } from "myria-core-sdk";

const env = EnvTypes.STAGING;

// manager example
const collectionManager: CollectionManager = new CollectionManager(env);

// IMyriaClient example
const client: IMyriaClient = {
provider: web3Instance.eth.currentProvider as any,
networkId: 5,
web3: web3Instance as any,
env: env
};

Myria client

Some of the functions in the SDK rely on MyriaClient. You can instantiate it as follows:

import { IMyriaClient, MyriaClient, EnvTypes } from "myria-core-sdk";
import Web3 from "web3";

// connect a MetaMask wallet
async function connectMetamask() {
if (typeof window.ethereum !== "undefined") {
const accounts = await window.ethereum.request({
method: "eth_requestAccounts",
});
if (accounts.length) {
console.log(accounts[0]);
}
} else {
console.log("No MetaMask detected. Please install it first and proceed!");
}
}

// instantiate a Web3 provider
function initWeb3Instance() {
let windowBrowser;
if (window && window.ethereum) {
windowBrowser = new Web3(Web3.givenProvider);
window.web3 = windowBrowser;
} else {
return;
}
return windowBrowser;
}

// instantiate a MyriaClient
async function getMyriaClient() {
const web3Instance = await initWeb3Instance();
const networkId = await web3Instance.eth.net.getId();

const client: IMyriaClient = {
provider: web3Instance.eth.currentProvider as any,
networkId,
web3: web3Instance as any,
env: EnvTypes.STAGING
};

const myriaClient = new MyriaClient(client);
return myriaClient;
}

// example
const client = await getMyriaClient();
const collectionManager: CollectionManager = new CollectionManager(client);

Response format

The response format is defined as follows:

Success response

{
"status": "success"
"data": [] | {},
"next": "key" | null // Optional for pagination
}

Error response

{
"status": "error"
"errors": [{ "code": $code, "title": "$title", "detail": "$error.message"}, ...{}]
}
tip

Note that some functions return different data formats representing smaller objects. Consider that during your application development and make sure to check response samples.