@zoralabs/protocol-sdk 0.5.1 → 0.5.3-MINT.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +18 -1
- package/README.md +86 -46
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/apis/chain-constants.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -8,9 +8,9 @@ $ tsup
|
|
|
8
8
|
[34mCLI[39m Cleaning output folder
|
|
9
9
|
[34mCJS[39m Build start
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m50.09 KB[39m
|
|
12
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m96.94 KB[39m
|
|
13
|
-
[32mCJS[39m ⚡️ Build success in 54ms
|
|
14
11
|
[32mESM[39m [1mdist/index.js [22m[32m46.17 KB[39m
|
|
15
12
|
[32mESM[39m [1mdist/index.js.map [22m[32m97.00 KB[39m
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 47ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m50.09 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m96.94 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 47ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
# @zoralabs/protocol-sdk
|
|
2
2
|
|
|
3
|
+
## 0.5.3-MINT.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [8dc4279c]
|
|
8
|
+
- @zoralabs/protocol-deployments@0.0.14-MINT.0
|
|
9
|
+
|
|
10
|
+
## 0.5.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 5c536dc: Update optimism eth constant
|
|
15
|
+
- Updated dependencies [f3332ee]
|
|
16
|
+
- Updated dependencies [d2085fd]
|
|
17
|
+
- Updated dependencies [a51a0cb]
|
|
18
|
+
- @zoralabs/1155-deployments@0.0.13
|
|
19
|
+
|
|
3
20
|
## 0.5.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
6
23
|
|
|
7
|
-
- 73070c0:
|
|
24
|
+
- 73070c0:
|
|
8
25
|
- Fix types export - make sure that types are exported to the correct directory. Broken by commit 627f8c37716f0b5c201f75ab1d025ae878be0ae29e7a269d21185fa04e4bcf93
|
|
9
26
|
- Exclude tests from built bundle
|
|
10
27
|
- Fixes #396
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Zora Protocol SDK
|
|
2
2
|
|
|
3
|
-
Protocol SDK allows
|
|
3
|
+
Protocol SDK allows developers to create tokens using the Zora Protocol and mint them.
|
|
4
4
|
|
|
5
5
|
## Installing
|
|
6
6
|
|
|
@@ -9,13 +9,13 @@ Protocol SDK allows users to create tokens using the Zora Protocol, and mint the
|
|
|
9
9
|
- `npm install viem`
|
|
10
10
|
- `npm install `
|
|
11
11
|
|
|
12
|
-
### Creating a mint from an on-chain contract
|
|
12
|
+
### Creating a mint from an on-chain contract
|
|
13
13
|
|
|
14
14
|
#### Using viem
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
```ts
|
|
17
|
-
import {createMintClient} from "@zoralabs/protocol-sdk";
|
|
18
|
-
import type {Address, PublicClient, WalletClient} from "viem";
|
|
17
|
+
import { createMintClient } from "@zoralabs/protocol-sdk";
|
|
18
|
+
import type { Address, PublicClient, WalletClient } from "viem";
|
|
19
19
|
|
|
20
20
|
async function mintNFT({
|
|
21
21
|
walletClient,
|
|
@@ -41,7 +41,7 @@ async function mintNFT({
|
|
|
41
41
|
// optional address that will receive a mint referral reward
|
|
42
42
|
mintReferral?: Address;
|
|
43
43
|
}) {
|
|
44
|
-
const mintClient = createMintClient({chain: walletClient.chain!});
|
|
44
|
+
const mintClient = createMintClient({ chain: walletClient.chain! });
|
|
45
45
|
|
|
46
46
|
// prepare the mint transaction, which can be simulated via an rpc with the public client.
|
|
47
47
|
const prepared = await mintClient.makePrepareMintTokenParams({
|
|
@@ -69,30 +69,47 @@ async function mintNFT({
|
|
|
69
69
|
const txHash = await walletClient.writeContract(request);
|
|
70
70
|
|
|
71
71
|
// wait for the transaction to be complete
|
|
72
|
-
await publicClient.waitForTransactionReceipt({hash: txHash});
|
|
72
|
+
await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
#### Using wagmi
|
|
77
77
|
|
|
78
78
|
```tsx
|
|
79
|
-
import {createMintClient} from "@zoralabs/protocol-sdk";
|
|
80
|
-
import {useEffect, useMemo, useState} from "react";
|
|
81
|
-
import {BaseError, SimulateContractParameters, stringify} from "viem";
|
|
82
|
-
import {
|
|
79
|
+
import { createMintClient } from "@zoralabs/protocol-sdk";
|
|
80
|
+
import { useEffect, useMemo, useState } from "react";
|
|
81
|
+
import { BaseError, SimulateContractParameters, stringify } from "viem";
|
|
82
|
+
import {
|
|
83
|
+
Address,
|
|
84
|
+
useAccount,
|
|
85
|
+
useContractWrite,
|
|
86
|
+
useNetwork,
|
|
87
|
+
usePrepareContractWrite,
|
|
88
|
+
usePublicClient,
|
|
89
|
+
useWaitForTransaction,
|
|
90
|
+
} from "wagmi";
|
|
83
91
|
|
|
84
92
|
// custom hook that gets the mintClient for the current chain
|
|
85
93
|
const useMintClient = () => {
|
|
86
94
|
const publicClient = usePublicClient();
|
|
87
95
|
|
|
88
|
-
const {chain} = useNetwork();
|
|
96
|
+
const { chain } = useNetwork();
|
|
89
97
|
|
|
90
|
-
const mintClient = useMemo(
|
|
98
|
+
const mintClient = useMemo(
|
|
99
|
+
() => chain && createMintClient({ chain, publicClient }),
|
|
100
|
+
[chain, publicClient],
|
|
101
|
+
);
|
|
91
102
|
|
|
92
103
|
return mintClient;
|
|
93
104
|
};
|
|
94
105
|
|
|
95
|
-
export const Mint = ({
|
|
106
|
+
export const Mint = ({
|
|
107
|
+
tokenId,
|
|
108
|
+
tokenContract,
|
|
109
|
+
}: {
|
|
110
|
+
tokenId: string;
|
|
111
|
+
tokenContract: Address;
|
|
112
|
+
}) => {
|
|
96
113
|
// call custom hook to get the mintClient
|
|
97
114
|
const mintClient = useMintClient();
|
|
98
115
|
|
|
@@ -102,7 +119,7 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
|
|
|
102
119
|
// params for the prepare contract write hook
|
|
103
120
|
const [params, setParams] = useState<SimulateContractParameters>();
|
|
104
121
|
|
|
105
|
-
const {address} = useAccount();
|
|
122
|
+
const { address } = useAccount();
|
|
106
123
|
|
|
107
124
|
useEffect(() => {
|
|
108
125
|
if (!mintClient || !address) return;
|
|
@@ -124,10 +141,14 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
|
|
|
124
141
|
makeParams();
|
|
125
142
|
}, [mintClient, address, quantityToMint]);
|
|
126
143
|
|
|
127
|
-
const {config} = usePrepareContractWrite(params);
|
|
144
|
+
const { config } = usePrepareContractWrite(params);
|
|
128
145
|
|
|
129
|
-
const {write, data, error, isLoading, isError} = useContractWrite(config);
|
|
130
|
-
const {
|
|
146
|
+
const { write, data, error, isLoading, isError } = useContractWrite(config);
|
|
147
|
+
const {
|
|
148
|
+
data: receipt,
|
|
149
|
+
isLoading: isPending,
|
|
150
|
+
isSuccess,
|
|
151
|
+
} = useWaitForTransaction({ hash: data?.hash });
|
|
131
152
|
|
|
132
153
|
return (
|
|
133
154
|
<>
|
|
@@ -139,7 +160,10 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
|
|
|
139
160
|
}}
|
|
140
161
|
>
|
|
141
162
|
{/* input for quantity to mint: */}
|
|
142
|
-
<input
|
|
163
|
+
<input
|
|
164
|
+
placeholder="quantity to mint"
|
|
165
|
+
onChange={(e) => setQuantityToMint(Number(e.target.value))}
|
|
166
|
+
/>
|
|
143
167
|
<button disabled={!write} type="submit">
|
|
144
168
|
Mint
|
|
145
169
|
</button>
|
|
@@ -161,7 +185,7 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
|
|
|
161
185
|
};
|
|
162
186
|
```
|
|
163
187
|
|
|
164
|
-
### Creating an 1155 contract
|
|
188
|
+
### Creating an 1155 contract
|
|
165
189
|
|
|
166
190
|
If an object with {name, uri} is passed in to this helper, it uses the creatorAccount and those values to either 1) create or 2) mint to that existing contract.
|
|
167
191
|
|
|
@@ -195,11 +219,11 @@ export async function createContract({
|
|
|
195
219
|
}
|
|
196
220
|
```
|
|
197
221
|
|
|
198
|
-
###
|
|
222
|
+
### Premint: create a mint without paying gas
|
|
199
223
|
|
|
200
224
|
```ts
|
|
201
|
-
import {createPremintClient} from "@zoralabs/protocol-sdk";
|
|
202
|
-
import type {Address, PublicClient, WalletClient} from "viem";
|
|
225
|
+
import { createPremintClient } from "@zoralabs/protocol-sdk";
|
|
226
|
+
import type { Address, PublicClient, WalletClient } from "viem";
|
|
203
227
|
|
|
204
228
|
async function createForFree({
|
|
205
229
|
walletClient,
|
|
@@ -213,7 +237,10 @@ async function createForFree({
|
|
|
213
237
|
// address of the token contract
|
|
214
238
|
creatorAccount: Address;
|
|
215
239
|
}) {
|
|
216
|
-
const premintClient = createPremintClient({
|
|
240
|
+
const premintClient = createPremintClient({
|
|
241
|
+
chain: walletClient.chain!,
|
|
242
|
+
publicClient,
|
|
243
|
+
});
|
|
217
244
|
|
|
218
245
|
// create and sign a free token creation.
|
|
219
246
|
const createdPremint = await premintClient.createPremint({
|
|
@@ -225,11 +252,13 @@ async function createForFree({
|
|
|
225
252
|
collection: {
|
|
226
253
|
contractAdmin: creatorAccount,
|
|
227
254
|
contractName: "Testing Contract",
|
|
228
|
-
contractURI:
|
|
255
|
+
contractURI:
|
|
256
|
+
"ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
|
|
229
257
|
},
|
|
230
258
|
// token info of token to create
|
|
231
259
|
tokenCreationConfig: {
|
|
232
|
-
tokenURI:
|
|
260
|
+
tokenURI:
|
|
261
|
+
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
|
|
233
262
|
},
|
|
234
263
|
});
|
|
235
264
|
|
|
@@ -243,19 +272,21 @@ async function createForFree({
|
|
|
243
272
|
tokenContractAddress: premintCollectionAddress,
|
|
244
273
|
};
|
|
245
274
|
}
|
|
246
|
-
|
|
247
275
|
```
|
|
248
276
|
|
|
249
|
-
### Updating a
|
|
277
|
+
### Updating a premint before it is brought onchain
|
|
250
278
|
|
|
251
|
-
Before a
|
|
279
|
+
Before a premint is brought onchain, it can be updated by the original creator of that token, by having that creator sign a message indicating the update. This is useful for updating the tokenURI, other metadata, or token sale configuration (price, duration, limits, etc.):
|
|
252
280
|
|
|
253
281
|
```ts
|
|
254
|
-
import {createPremintClient} from "@zoralabs/protocol-sdk";
|
|
255
|
-
import type {Address, PublicClient, WalletClient} from "viem";
|
|
282
|
+
import { createPremintClient } from "@zoralabs/protocol-sdk";
|
|
283
|
+
import type { Address, PublicClient, WalletClient } from "viem";
|
|
256
284
|
|
|
257
|
-
async function updateCreatedForFreeToken(
|
|
258
|
-
|
|
285
|
+
async function updateCreatedForFreeToken(
|
|
286
|
+
walletClient: WalletClient,
|
|
287
|
+
premintUid: number,
|
|
288
|
+
) {
|
|
289
|
+
const premintClient = createPremintClient({ chain: walletClient.chain! });
|
|
259
290
|
|
|
260
291
|
// sign a message to update the created for free token, and store the update
|
|
261
292
|
await premintClient.updatePremint({
|
|
@@ -265,19 +296,20 @@ async function updateCreatedForFreeToken(walletClient: WalletClient, premintUid:
|
|
|
265
296
|
walletClient,
|
|
266
297
|
// Token information, falls back to defaults set in DefaultMintArguments.
|
|
267
298
|
tokenConfigUpdates: {
|
|
268
|
-
tokenURI:
|
|
299
|
+
tokenURI:
|
|
300
|
+
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
|
|
269
301
|
},
|
|
270
302
|
});
|
|
271
303
|
}
|
|
272
304
|
```
|
|
273
305
|
|
|
274
|
-
### Deleting a
|
|
306
|
+
### Deleting a premint before it is brought onchain
|
|
275
307
|
|
|
276
|
-
Before a
|
|
308
|
+
Before a premint is brought onchain, it can be deleted by the original creator of that token, by having that creator sign a message indicating the deletion:
|
|
277
309
|
|
|
278
310
|
```ts
|
|
279
311
|
async function deleteCreatedForFreeToken(walletClient: WalletClient) {
|
|
280
|
-
const premintClient = createPremintClient({chain: walletClient.chain!});
|
|
312
|
+
const premintClient = createPremintClient({ chain: walletClient.chain! });
|
|
281
313
|
|
|
282
314
|
// sign a message to delete the premint, and store the deletion
|
|
283
315
|
await premintClient.deletePremint({
|
|
@@ -290,14 +322,18 @@ async function deleteCreatedForFreeToken(walletClient: WalletClient) {
|
|
|
290
322
|
}
|
|
291
323
|
```
|
|
292
324
|
|
|
293
|
-
### Minting a
|
|
325
|
+
### Minting a premint and bringing it onchain
|
|
294
326
|
|
|
295
327
|
```ts
|
|
296
|
-
import {createPremintClient} from "@zoralabs/protocol-sdk";
|
|
297
|
-
import type {Address, PublicClient, WalletClient} from "viem";
|
|
328
|
+
import { createPremintClient } from "@zoralabs/protocol-sdk";
|
|
329
|
+
import type { Address, PublicClient, WalletClient } from "viem";
|
|
298
330
|
|
|
299
|
-
async function mintCreatedForFreeToken(
|
|
300
|
-
|
|
331
|
+
async function mintCreatedForFreeToken(
|
|
332
|
+
walletClient: WalletClient,
|
|
333
|
+
publicClient: PublicClient,
|
|
334
|
+
minterAccount: Address,
|
|
335
|
+
) {
|
|
336
|
+
const premintClient = createPremintClient({ chain: walletClient.chain! });
|
|
301
337
|
|
|
302
338
|
const simulateContractParameters = await premintClient.makeMintParameters({
|
|
303
339
|
minterAccount,
|
|
@@ -310,15 +346,19 @@ async function mintCreatedForFreeToken(walletClient: WalletClient, publicClient:
|
|
|
310
346
|
});
|
|
311
347
|
|
|
312
348
|
// simulate the transaction and get any validation errors
|
|
313
|
-
const {request} = await publicClient.simulateContract(
|
|
349
|
+
const { request } = await publicClient.simulateContract(
|
|
350
|
+
simulateContractParameters,
|
|
351
|
+
);
|
|
314
352
|
|
|
315
353
|
// submit the transaction to the network
|
|
316
354
|
const txHash = await walletClient.writeContract(request);
|
|
317
355
|
|
|
318
356
|
// wait for the transaction to be complete
|
|
319
|
-
const receipt = await publicClient.waitForTransactionReceipt({
|
|
357
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
358
|
+
hash: txHash,
|
|
359
|
+
});
|
|
320
360
|
|
|
321
|
-
const {urls} = await premintClient.getDataFromPremintReceipt(receipt);
|
|
361
|
+
const { urls } = await premintClient.getDataFromPremintReceipt(receipt);
|
|
322
362
|
|
|
323
363
|
// block explorer url:
|
|
324
364
|
console.log(urls.explorer);
|
|
@@ -327,4 +367,4 @@ async function mintCreatedForFreeToken(walletClient: WalletClient, publicClient:
|
|
|
327
367
|
// manage url:
|
|
328
368
|
console.log(urls.zoraManage);
|
|
329
369
|
}
|
|
330
|
-
```
|
|
370
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -512,7 +512,7 @@ var networkConfigByChain = {
|
|
|
512
512
|
[import_chains.optimism.id]: {
|
|
513
513
|
chainId: import_chains.optimism.id,
|
|
514
514
|
isTestnet: false,
|
|
515
|
-
zoraCollectPathChainName: "
|
|
515
|
+
zoraCollectPathChainName: "oeth",
|
|
516
516
|
zoraBackendChainName: "OPTIMISM-MAINNET",
|
|
517
517
|
subgraphUrl: getSubgraph("zora-create-optimism", "stable")
|
|
518
518
|
},
|