IP‑On‑Chain — Usage Recipes¶
Assumes a dev node on
ws://127.0.0.1:59090
and the pallet prefixipOnchain
at the metadata level.
First of all, you need to follow Getting started guide to build Mubert Node
Get types¶
WS=${WS_ENDPOINT:-ws://127.0.0.1:59090}
npx polkadot-types-from-chain --endpoint "$WS" --output src/types --package @local/typedefs
Add a new Authority¶
TypeScript¶
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
const api = await ApiPromise.create({ provider: new WsProvider(WS_ENDPOINT) });
const keys = new Keyring({ type: "sr25519" });
const alice = keys.addFromUri("//Alice"); // will become `owner`
await api.tx.ipOnchain
.createAuthority("test_authority", alice.addressRaw, "Musician")
.signAndSend(alice, ({ status }) => {
if (status.isInBlock) console.log("Authority added", status.asInBlock.toHex());
});
Create a new Entity¶
await api.tx.ipOnchain.createEntity(
/* kind */ "Track", // IPEntityKind
/* owner */ 0, // must reference an Authority owner-id
/* url */ "https://metadata.mubert.xyz/0.json", // Should be MM25 Metadata format url or CID
/* standard */ "MM25" // MetadataStandard enum
).signAndSend(alice);
Validate data with RPC call¶
Request:
curl -s -H "Content-Type: application/json" -d '{"id":99, "jsonrpc":"2.0", "method": "ipOnchain_entities", "params": [0,1]}' "http://127.0.0.1:49423"
Expected Response:
{"jsonrpc":"2.0","id":99,"result":[[0,{"entity_kind":"Track","owner":3348313556,"authors":null,"royalty_parts":null,"related_to":null,"metadata":{"url":[104,116,116,112,115,58,47,47,109,101,116,97,100,97,116,97,46,109,117,98,101,114,116,46,120,121,122,47,48,46,106,115,111,110],"standard":"MM25"}}]]}