Create a PIL Policy

This section demonstrates how to create a policy with PIL licensing framework parameters that follows the pre-set Non-Commercial Social Remixing license

📘

Before Reading

It's important to note that it would be very rare for you to have to use this function. A PIL Policy, which is defined by its parameters, only has to be created once. Thus, it is very likely it has already been created by someone else.

You can view a list of popular premade policyies here.

Prerequisites

  • Setup the client object.
  • Understand the concept of policies and licenses.
  • If a PIL policy already exists for the identical set of parameters you intend to create, it is unnecessary to create it again and the function will error. You can simply use an existing policy by its policyId.

Create a Non-Commercial Social Remixing Policy

To create a PIL policy that adheres to the pre-set Non-Commercial Social Remixing Policy, we first construct an object that consists of the relevant policy parameters we intend to set explicitly.

:information-source: If the provided policy parameters have already been created before (by anyone), the response object will contain the policyId of the existing policy so you can use that instead.

const nonCommercialSocialRemixingParams = {
  attribution: true, // Whether or not attribution is required when reproducing the work
  commercialUse: false, // Whether or not the work can be used commercially
  derivativesAttribution: true, // Whether or not attribution is required for derivatives of the work
  derivativesAllowed: true, // Whether or not the licensee can create derivatives of the work
  derivativesApproval: true, // Whether or not the licensor must approve derivatives of the work before they can be
  derivativesReciprocal: true, // Whether or not the licensee must license derivatives of the work under the same terms
}

const response = await client.policy.registerPILPolicy({
  ...nonCommercialSocialRemixingParams,
  txOptions: { waitForTransaction: true }
});

console.log(`PIL Policy registered at transaction hash ${response.txHash}, Policy ID: ${response.policyId}`) 
export type RegisterPILPolicyRequest = {
  transferable: boolean;
  royaltyPolicy?: `0x${string}`;
  mintingFee?: number;
  mintingFeeToken?: `0x${string}`;
  attribution?: boolean;
  commercialUse?: boolean;
  commercialAttribution?: boolean;
  commercialRevShare?: number;
  derivativesAllowed?: boolean;
  derivativesAttribution?: boolean;
  derivativesApproval?: boolean;
  derivativesReciprocal?: boolean;
  territories?: string[];
  distributionChannels?: string[];
  contentRestrictions?: string[];
  commercializerChecker?: `0x${string}`;
  commercializerCheckerData?: string;
  txOptions?: TxOptions;
};

export type RegisterPILPolicyResponse = {
  txHash: string;
  policyId?: string;
};

Setting waitForTransaction: true in the transaction options will return the policyId value.