Register A Relationship

Register a relationship

🚧

This is a SDK for Alpha

This SDK is alpha and not production complete yet, which means that we could change the schemas, smart contract deployment and backend endpoints that at any time without warning or notice to you. When this SDK is production ready, we will remove this warning and will endeavor to ensure the production quality of the SDK and update the SDK in regular basis with formal notice.

Developers can use the RelationshipClient to create a relationship between two entities with its register function. The supported entities for relationship are:

  • IP Assets
  • IP Orgs
  • Licenses
  • Account addresses
  • External NFTs

Please keep in mind that a relationship is directional. The source entity to destination entity.

Usage

const { txHash } = await client.relationship.register({
  ipOrgId,
  relType,
  srcContract,
  srcTokenId,
  dstContract,
  dstTokenId,
  preHookData,
  postHookData,
  txOptions,
});

Parameters

  • ipOrgId: string: The IP Org ID.
  • relType: string: The relationship type string of the relationship to be registered. E.g. APPEAR_IN.
  • srcContract: string: The smart contract address of the source entity registry. For example, the proxy smart contract of IP Asset Registry.
  • srcTokenId: string: The token ID of the source entity to be related. For example, the token ID of the IP Asset.
  • dstContract: string: The smart contract address of the destination entity registry.
  • dstTokenId: string: The token ID of the destination entity to be related.
  • preHookData: Array<Record<string, unknown>>: An array of data passed into the pre-action hooks.
  • postHookData: Array<Record<string, unknown>>: An array of data passed into the post-action hooks.
  • txOptions: TxOption: the transaction option: whether or not to wait for the transaction complete.

Response

  • txHash: string: The transaction hash of the operation.
  • relationshipId: string: The ID of the relationship just created. It will be empty if waitForTransaction in txOption is set to false.

Example

You can refer to the source code below to call register function of RelationshipClient:

// Register a relationship
client.relationship.register({
  ipOrgId: "0x86310d77f44e66d2db850266f3f600256d123579",
  relType: "APPEAR_IN",
  srcContract: IP_ASSET_REGISTRY_CONTRACT,
  srcTokenId: "1",
  dstContract: IP_ASSET_REGISTRY_CONTRACT,
  dstTokenId: "2",
  preHookData: [],
  postHookData: [],
  txOptions: {waitForTransaction: true}
}).then(({txHash, relationshipId}) => {
  console.log("txHash", txHash);
  console.log("relationshipId", relationshipId);
});

The output of running above code will return the transaction hash and the relationship ID:

txHash: 0xe6ebc5b23e6610fb5f3458b9421de230684fa25555889585af50a2bdf277cbf8
ipAssetId: 193

For the full source of the example, please refer to this link.