SPG Functions
A group of functions provided by the Story Protocol Gateway (SPG) contract, which is essentially a way to combine independent operations like Register an NFT as an IP Asset and Attach License Terms to an IP Asset into one transaction to make your life easier.
Warning!
While these functions are publicly supported in SDK, it is recommended to NOT use them in your applications yet. They are still being tested.
Things like the IP-related metadata, represented in the
metadata
andmetadataURI
fields you'll see below, do not have official standards yet although we are working on them.
Prerequisites
- Setup the client object.
Mint + Register + Metadata + Attach Terms
This function allows you to do all of the following:
Mint an NFT ▶️ Register an NFT as an IP Asset ▶️ Add Metadata to an IP Asset ▶️ Attach License Terms to an IP Asset
import { PIL_TYPE } from '@story-protocol/core-sdk';
import { toHex } from 'viem';
const response = await client.ipAsset.mintAndRegisterIpAssetWithPilTerms({
nftContract: "0xd516482bef63Ff19Ed40E4C6C2e626ccE04e19ED", // your NFT contract address
pilType: PIL_TYPE.NON_COMMERCIAL_REMIX,
metadata: {
metadataURI: 'test-uri', // uri of IP metadata
metadataHash: toHex('test-metadata-hash', { size: 32 }), // hash of IP metadata
nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }), // hash of NFT metadata
},
txOptions: { waitForTransaction: true }
});
console.log(`Completed at transaction hash ${response.txHash}, NFT Token ID: ${response.tokenId}, IPA ID: ${response.ipId}, License Terms ID: ${response.licenseTermsId}`);
export type CreateIpAssetWithPilTermsRequest = {
nftContract: Address;
pilType: PIL_TYPE;
metadata?: {
metadataURI?: string;
metadataHash?: Hex;
nftMetadataHash?: Hex;
};
recipient?: Address;
mintingFee?: string;
currency?: Address;
commercialRevShare?: number;
txOptions?: TxOptions;
};
export type CreateIpAssetWithPilTermsResponse = {
txHash: string;
ipId?: Address;
tokenId?: bigint;
licenseTermsId?: bigint;
};
Register + Metadata + Attach Terms
This function allows you to do all of the following:
Register an NFT as an IP Asset ▶️ Add Metadata to an IP Asset ▶️ Attach License Terms to an IP Asset
import { PIL_TYPE } from '@story-protocol/core-sdk';
import { toHex } from 'viem';
const response = await client.ipAsset.registerIpAndAttachPilTerms({
nftContract: "0xd516482bef63Ff19Ed40E4C6C2e626ccE04e19ED", // your NFT contract address
tokenId: '127',
pilType: PIL_TYPE.NON_COMMERCIAL_REMIX,
metadata: {
metadataURI: 'test-uri', // uri of IP metadata
metadataHash: toHex('test-metadata-hash', { size: 32 }), // hash of IP metadata
nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }), // hash of NFT metadata
},
txOptions: { waitForTransaction: true }
});
console.log(`Completed at transaction hash ${response.txHash}, IPA ID: ${response.ipId}, License Terms ID: ${response.licenseTermsId}`);
export type RegisterIpAndAttachPilTermsRequest = {
nftContract: Address;
tokenId: bigint | string | number;
pilType: PIL_TYPE;
deadline?: bigint | number | string;
mintingFee?: string;
currency?: Address;
commercialRevShare?: number;
metadata?: {
metadataURI?: string;
metadataHash?: Hex;
nftMetadataHash?: Hex;
};
txOptions?: TxOptions;
};
export type RegisterIpAndAttachPilTermsResponse = {
txHash: string;
ipId?: Address;
licenseTermsId?: bigint;
};
Register + Derivative
This function allows you to do all of the following:
Register an NFT as an IP Asset ▶️ Register an IPA as a Derivative
import { PIL_TYPE } from '@story-protocol/core-sdk';
import { toHex } from 'viem';
const response = await client.ipAsset.registerDerivativeIp({
nftContract: "0xd516482bef63Ff19Ed40E4C6C2e626ccE04e19ED", // your NFT contract address
tokenId: '127',
derivData: {
parentIpIds: ['0x4c1f8c1035a8cE379dd4ed666758Fb29696CF721'],
licenseTermsIds: ['13']
},
metadata: {
metadataURI: 'test-uri', // uri of IP metadata
metadataHash: toHex('test-metadata-hash', { size: 32 }), // hash of IP metadata
nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }), // hash of NFT metadata
},
txOptions: { waitForTransaction: true }
});
console.log(`Completed at transaction hash ${response.txHash}, IPA ID: ${response.ipId}`);
export type RegisterIpAndMakeDerivativeRequest = {
nftContract: Address;
tokenId: string | number | bigint;
deadline?: string | number | bigint;
derivData: {
parentIpIds: Address[];
licenseTermsIds: string[] | bigint[] | number[];
licenseTemplate?: Address;
};
metadata?: {
metadataURI?: string;
metadataHash?: Hex;
nftMetadataHash?: Hex;
};
txOptions?: TxOptions;
};
export type RegisterIpAndMakeDerivativeResponse = {
txHash: string;
ipId?: Address;
};
Updated about 2 months ago