SPG 함수

Story Protocol Gateway(SPG) 계약에서 제공하는 일련의 기능으로, 기본적으로 NFT를 IP Asset을 라이선스 조건을 추가하는 등 하나 하나의 작업을 하나의 트랜잭션으로 만드는 함수.

0) Prerequisites

1) 민팅 + 등록 + 약관 첨부하기

이 함수를 사용함으로서, 다음 모든 작업을 한번에 해 낼 수 있다. NFT 민팅 -> IP Asset 등록하기 -> IP Asset에 약관 첨부하기

이 함수를 사용하기 전에

nftContract 주소는 반드시 ISPGNFT로 구현되어야 한다.

ISPGNFT 콜렉션을 만들 때, SPG contract내에 있는 createCollection을 사용하면 쉽게 만들 수 있다.

NFT Metadata

이 함수는 NFT의 tokenUriipMetadata.nftMetadataURI에 전달된 값으로 설정되는 점을 유의해야 한다.

import { PIL_TYPE } from '@story-protocol/core-sdk';
import { toHex, Address } from 'viem';

const newCollection = await client.nftClient.createNFTCollection({ 
  name: 'Test NFT', 
  symbol: 'TEST', 
  txOptions: { waitForTransaction: true } 
});

const response = await client.ipAsset.mintAndRegisterIpAssetWithPilTerms({
  // an NFT contract address created by the SPG
  nftContract: newCollection.nftContract as Address,
  pilType: PIL_TYPE.NON_COMMERCIAL_REMIX,
  // https://docs.story.foundation/docs/ipa-metadata-standard
  ipMetadata: {
    ipMetadataURI: 'test-uri',
    ipMetadataHash: toHex('test-metadata-hash', { size: 32 }),
    nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }),
    nftMetadataURI: 'test-nft-uri',
  },
  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}`);
Request Type
export type CreateIpAssetWithPilTermsRequest = {
  nftContract: Address;
  pilType: PIL_TYPE;
  currency?: Address;
  mintingFee?: string | number | bigint;
  recipient?: Address;
  commercialRevShare?: number;
  nftMetadata?: string;
} & IpMetadataAndTxOption;

type IpMetadataAndTxOption = {
  ipMetadata?: {
    ipMetadataURI?: string;
    ipMetadataHash?: Hex;
    nftMetadataURI?: string;
    nftMetadataHash?: Hex;
  };
  txOptions?: TxOptions;
};
Response Type
export type CreateIpAssetWithPilTermsResponse = {
  txHash?: string;
  encodedTxData?: EncodedTxData;
  ipId?: Address;
  tokenId?: bigint;
  licenseTermsId?: bigint;
};

2) 등록 + 약관 첨부하기

이 함수를 사용함으로서, 다음 모든 작업을 한번에 해 낼 수 있다. IP Asset 등록하기 -> 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,
  // https://docs.story.foundation/docs/ipa-metadata-standard
  ipMetadata: {
    ipMetadataURI: 'test-uri',
    ipMetadataHash: toHex('test-metadata-hash', { size: 32 }),
    nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }),
    nftMetadataURI: 'test-nft-uri',
  },
  txOptions: { waitForTransaction: true }
});

console.log(`Completed at transaction hash ${response.txHash}, IPA ID: ${response.ipId}, License Terms ID: ${response.licenseTermsId}`);
Request Type
export type RegisterIpAndAttachPilTermsRequest = {
  nftContract: Address;
  tokenId: bigint | string | number;
  pilType: PIL_TYPE;
  mintingFee: string | number | bigint;
  currency: Address;
  deadline?: bigint | number | string;
  commercialRevShare?: number;
} & IpMetadataAndTxOption;

type IpMetadataAndTxOption = {
  ipMetadata?: {
    ipMetadataURI?: string;
    ipMetadataHash?: Hex;
    nftMetadataURI?: string;
    nftMetadataHash?: Hex;
  };
  txOptions?: TxOptions;
};
Response Type
export type RegisterIpAndAttachPilTermsResponse = {
  txHash?: string;
  encodedTxData?: EncodedTxData;
  ipId?: Address;
  licenseTermsId?: bigint;
};

3) 등록 + Derivative

이 함수를 사용함으로서, 다음 모든 작업을 한번에 해 낼 수 있다. IP Asset 등록하기 -> Register an IPA as a Derivative

import { toHex } from 'viem';

const response = await client.ipAsset.registerDerivativeIp({
  nftContract: "0xd516482bef63Ff19Ed40E4C6C2e626ccE04e19ED", // your NFT contract address
  tokenId: '127',
  derivData: {
    parentIpIds: ['0x4c1f8c1035a8cE379dd4ed666758Fb29696CF721'],
    licenseTermsIds: ['13']
  },
  // https://docs.story.foundation/docs/ipa-metadata-standard
  ipMetadata: {
    ipMetadataURI: 'test-uri',
    ipMetadataHash: toHex('test-metadata-hash', { size: 32 }),
    nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }),
    nftMetadataURI: 'test-nft-uri',
  },
  txOptions: { waitForTransaction: true }
});

console.log(`Completed at transaction hash ${response.txHash}, IPA ID: ${response.ipId}`);
Request Type
export type RegisterIpAndMakeDerivativeRequest = {
  nftContract: Address;
  tokenId: string | number | bigint;
  deadline?: string | number | bigint;
  derivData: {
    parentIpIds: Address[];
    licenseTermsIds: string[] | bigint[] | number[];
    licenseTemplate?: Address;
  };
} & IpMetadataAndTxOption;

type IpMetadataAndTxOption = {
  ipMetadata?: {
    ipMetadataURI?: string;
    ipMetadataHash?: Hex;
    nftMetadataURI?: string;
    nftMetadataHash?: Hex;
  };
  txOptions?: TxOptions;
};
Response Type
export type RegisterIpAndMakeDerivativeResponse = {
  txHash?: string;
  encodedTxData?: EncodedTxData;
  ipId?: Address;
};

4) 민팅 + 등록 + Derivative

이 함수를 사용함으로서, 다음 모든 작업을 한번에 해 낼 수 있다. NFT 민팅 -> IP Asset 등록하기 -> Register an IPA as a Derivative

이 함수를 사용하기 전에

nftContract 주소는 반드시 ISPGNFT로 구현되어야 한다.

ISPGNFT 콜렉션을 만들 때, SPG contract내에 있는 createCollection을 사용하면 쉽게 만들 수 있다.

NFT Metadata

이 함수는 NFT의 tokenUriipMetadata.nftMetadataURI에 전달된 값으로 설정되는 점을 유의해야 한다.

import { PIL_TYPE } from '@story-protocol/core-sdk';
import { toHex } from 'viem';

const response = await client.ipAsset.mintAndRegisterIpAndMakeDerivative({
  // an NFT contract address created by the SPG
  nftContract: "0xd516482bef63Ff19Ed40E4C6C2e626ccE04e19ED",
  derivData: {
    parentIpIds: ['0x4c1f8c1035a8cE379dd4ed666758Fb29696CF721'],
    licenseTermsIds: ['13']
  },
  // https://docs.story.foundation/docs/ipa-metadata-standard
  ipMetadata: {
    ipMetadataURI: 'test-uri',
    ipMetadataHash: toHex('test-metadata-hash', { size: 32 }),
    nftMetadataHash: toHex('test-nft-metadata-hash', { size: 32 }),
    nftMetadataURI: 'test-nft-uri',
  },
  txOptions: { waitForTransaction: true }
});

console.log(`Completed at transaction hash ${response.txHash}, IPA ID: ${response.ipId}`);
Request Type
export type MintAndRegisterIpAndMakeDerivativeRequest = {
  nftContract: Address;
  derivData: {
    parentIpIds: Address[];
    licenseTermsIds: string[] | bigint[] | number[];
    licenseTemplate?: Address;
  };
  nftMetadata?: string;
  recipient?: Address;
} & IpMetadataAndTxOption;

type IpMetadataAndTxOption = {
  ipMetadata?: {
    ipMetadataURI?: string;
    ipMetadataHash?: Hex;
    nftMetadataURI?: string;
    nftMetadataHash?: Hex;
  };
  txOptions?: TxOptions;
};
Response Type
export type RegisterDerivativeResponse = {
  txHash?: string;
  encodedTxData?: EncodedTxData;
  childIpId?: Address;
};

Last updated