1import dotenv from 'dotenv';
2dotenv.config();
3
4import pkg from '@story-protocol/core-sdk';
5const { StoryClient, IpMetadata, LicenseTerms } = pkg;
6import { http } from "viem";
7import { privateKeyToAccount } from "viem/accounts";
8import { uploadJSONToIPFS } from "./utils/uploadToIpfs.js";
9import { createHash } from "crypto";
10
11
12const privateKey = `0x${process.env.WALLET_PRIVATE_KEY}`;
13const account = privateKeyToAccount(privateKey);
14
15const config = {
16 account: account,
17 transport: http(process.env.RPC_PROVIDER_URL),
18 chainId: "odyssey",
19};
20
21const client = new StoryClient(config);
22
23
24console.log(client);
25
26
27async function registerImageAsIP(cid, title, description) {
28 const ipMetadata = {
29 title: title,
30 description: description,
31 ipType: 'image',
32 attributes: [
33 {
34 key: 'Model',
35 value: 'Stability',
36 },
37 {
38 key: 'Service',
39 value: 'Stable Image Core'
40 },
41 {
42 key: 'Prompt',
43 value: 'Lighthouse on a cliff overlooking the ocean',
44 },
45 ],
46 creators: [
47 {
48 name: 'zstake',
49 contributionPercent: 100,
50 address: account.address,
51 },
52 ],
53 };
54
55 const nftMetadata = {
56 name: 'NFT representing ownership of our image',
57 description: 'This NFT represents ownership of the image generated by Stability',
58 image: process.env.PINATA_GATEWAY + '/files/' + cid,
59 attributes: [
60 {
61 key: 'Model',
62 value: 'Stability',
63 },
64 {
65 key: 'Service',
66 value: 'Stable Image Core'
67 },
68 {
69 key: 'Prompt',
70 value: 'Lighthouse on a cliff overlooking the ocean',
71 },
72 ]
73 };
74
75 try {
76
77 const ipIpfsHash = await uploadJSONToIPFS(ipMetadata);
78 const ipHash = createHash("sha256")
79 .update(JSON.stringify(ipMetadata))
80 .digest("hex");
81
82
83 const nftIpfsHash = await uploadJSONToIPFS(nftMetadata);
84 const nftHash = createHash("sha256")
85 .update(JSON.stringify(nftMetadata))
86 .digest("hex");
87
88 console.log(`IP metadata IPFS hash: ${ipIpfsHash}`);
89 console.log(`IP metadata SHA-256 hash: ${ipHash}`);
90 console.log(`NFT metadata IPFS hash: ${nftIpfsHash}`);
91 console.log(`NFT metadata SHA-256 hash: ${nftHash}`);
92
93
94
95
96 } catch (error) {
97 console.error('Error registering image as IP:', error);
98 }
99}
100
101
102const royaltyPolicyLAPAddress = '0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6';
103const susdAddress = '0xC0F6E387aC0B324Ec18EAcf22EE7271207dCE3d5';
104
105const commercialRemixTerms = {
106 transferable: true,
107 royaltyPolicy: '0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6',
108 defaultMintingFee: BigInt(10),
109 expiration: BigInt(0),
110 commercialUse: true,
111 commercialAttribution: true,
112 commercializerChecker: '0x0000000000000000000000000000000000000000',
113 commercializerCheckerData: '0x0000000000000000000000000000000000000000',
114 commercialRevShare: 50,
115 commercialRevCeiling: BigInt(0),
116 derivativesAllowed: true,
117 derivativesAttribution: true,
118 derivativesApproval: false,
119 derivativesReciprocal: true,
120 derivativeRevCeiling: BigInt(0),
121 currency: susdAddress,
122 uri: '',
123}
124
125
126async function registerLicenseTerms() {
127 try {
128
129
130
131 } catch (error) {
132 console.error('Error registering license terms:', error);
133 }
134}
135
136
137const cid = 'YOUR CID';
138const title = 'YOUR Titile';
139const description = '~~~';
140
141registerImageAsIP(cid, title, description);
142registerLicenseTerms();
143