@cdr-kit/react/Hooks/useAttachLicenseTerms

useAttachLicenseTerms

Attach an existing PIL licenseTermsId to an IP asset — required before any buyer can mintLicenseTokens against it. Idempotent: calling twice with the same args is a no-op tx.
import { useAttachLicenseTerms } from "@cdr-kit/react"

Signature

type
function useAttachLicenseTerms(client: StoryClient | undefined): {
attach: (params: {
  ipId: Hex;
  licenseTermsId: bigint;
  licenseTemplate?: Hex;   // defaults to the canonical PIL template
}) => Promise<{ txHash: Hex }>;
isLoading: boolean;
error?: Error;
};

Example

tsx
import { useStoryClient, useAttachLicenseTerms } from "@cdr-kit/react";

function AttachTerms({ ipId, licenseTermsId }) {
const client = useStoryClient();
const { attach, isLoading, error } = useAttachLicenseTerms(client);
return (
  <>
    <button
      disabled={!client || isLoading}
      onClick={() => attach({ ipId, licenseTermsId })}
    >
      {isLoading ? "attaching…" : "attach PIL terms"}
    </button>
    {error && <span>{error.message}</span>}
  </>
);
}

Call ordering

The flow is: (1) registerIpAsset → ipId, (2) registerPilTerms → licenseTermsId (or use a previously registered set), (3) attachLicenseTerms links the two. Only then can buyers mint license tokens against your IP.

License template

licenseTemplate defaults to the canonical Story PIL template. Override only if you've registered a custom template at the protocol level — rare.