Skip to main content

Quickstart: Typescript npm

The OPENFORMAT Typescript SDK provides a simple way to interact with OPENFORMAT.

Don't forget to checkout our React SDK which simplifies using the SDK even further.

Installation

You can install the SDK with NPM or Yarn.

npm install @openformat/sdk ethers@^5

Setup

Constellations

A Constellation in our ecosystem is a metaphorical representation of a core or parent contract, acting as a central hub that governs and coordinates a collection of child contracts, referred to as "stars." Think of a Constellation as an application or organisational suite that houses various features or modules.

Features of a Constellation:

  • Fungible Token Integration: Each Constellation has its own fungible token associated with it. This token can represent value, ownership, or participation within the Constellation's ecosystem.
  • Modularity: Constellations are designed to host multiple stars. This allows for an expandable and customizable system where different functionalities can be added or removed as stars.
  • Interoperability: The design ensures that each Star within a Constellation can interact seamlessly with each other by using the Constellation Token. This token becomes a universal medium of exchange, collaboration, and communication among stars, enabling them to share information and functionality as defined by the Constellation.

Stars

Stars are child contracts connected to a Constellation. They represent individual features, applications, or components that operate under the governance of the parent Constellation. Each Star is like a unique tool or service within the broader application suite.

Features of a Star:

  • Independence: Though governed by the Constellation, each Star can have its own logic, data, and functionality. This enables developers to create diverse and specialized modules.
  • Interaction with Constellation Token: Stars can interact with the fungible token of the parent Constellation. This can be leveraged for various purposes, such as payment or access control within a Star.
  • Integration: Stars are fully integrated within the Constellation, allowing for seamless communication and collaboration with other stars in the same Constellation via the Constellation token.
  • Upgradeability: Depending on the design of the Constellation, stars can be added, removed, or updated without disrupting the entire system.

By organising your smart contracts into constellations and stars, you provide a hierarchical and modular system that promotes scalability, customisation, and efficient management. These concepts align well with both the technical architecture and the real-world analogies they represent, facilitating understanding and engagement with your ecosystem.

Creating Constellations and Stars

Join Our Dashboard Private Beta

Our Dashboard for creating and managing Constellations and Stars is now available in private beta. This innovative tool allows you to easily build and oversee your ecosystem without writing a single line of code. If you're interested in joining our beta program and exploring these powerful features, please email us at dev@openformat.tech.

Before interacting with the OPENFORMAT protocol, you first need to deploy a Constellation and Star.

import { Chains, OpenFormatSDK } from "@openformat/sdk";

const sdk = new OpenFormatSDK({
network: Chains.polygonMumbai,
starId: "", // Pass an empty string here for Constellation and Star creation
signer: process.env.PRIVATE_KEY, // Your wallet's private key
});

const constellation = await sdk.factory.createConstellation({
name: "CONSTELLATION",
symbol: "CONST",
decimals: 18,
supply: 1000,
});

const star = await sdk.factory.createStar({
name: "STAR",
constellation: constellation.constellationAddress,
owner: "YOUR_WALLET_ADDRESS",
});

console.log({
constellation: constellation.constellationAddress,
star: star.starAddress,
});

Initialising the SDK

You can initialise the SDK by creating a new instance of OpenFormatSDK and selecting one of the available networks that are supported. This will create a new instance in "read-only" mode, meaning you can read from the subgraph but any interactions that require you to sign a transaction (deploying a new instance of the contract, minting an NFT, etc...) will throw an error.

import { OpenFormatSDK, Chains } from "@openformat/sdk";

const sdk = new OpenFormatSDK({
network: Chains.polygonMumbai,
starId: "YOUR_STAR_ID",
});

If you wish to do more than just interact with the subgraph, you will have to provide a signer when initialising the SDK.

The easiest way to do this is by passing your wallet's private key as the signer. You'd typically do this only from a Node.js context as to not expose your private key to the world.

import { OpenFormatSDK, Chains } from "@openformat/sdk";

const sdk = new OpenFormatSDK({
network: Chains.polygonMumbai,
starId: "YOUR_STAR_ID",
signer: process.env.PRIVATE_KEY, // Your wallet's private key
});
private keys

NEVER pass a private key when initialising the SDK in the client, as this is something that you DO NOT want to expose to the world.