@@ -214,53 +214,71 @@ export async function createContract({
214214}
215215```
216216
217- ### Creating a premint :
217+ ### Creating a token for free (gasless creation) :
218218
219219``` ts
220- import { PremintAPI } from " @zoralabs/protocol-sdk" ;
221- import type { Address , WalletClient } from " viem" ;
220+ import {createPremintClient } from " @zoralabs/protocol-sdk" ;
221+ import type {Address , PublicClient , WalletClient } from " viem" ;
222222
223- async function makePremint(walletClient : WalletClient ) {
224- // Create premint
225- const premint = await createPremintAPI (walletClient .chain ).createPremint ({
226- // Extra step to check the signature on-chain before attempting to sign
223+ async function createForFree({
224+ walletClient ,
225+ creatorAccount ,
226+ }: {
227+ // wallet client that will submit the transaction
228+ walletClient: WalletClient ;
229+ // address of the token contract
230+ creatorAccount: Address ;
231+ }) {
232+ const premintClient = createPremintClient ({ chain: walletClient .chain ! });
233+
234+ // create and sign a free token creation.
235+ const createdPremint = await premintClient .createPremint ({
236+ walletClient ,
237+ account: creatorAccount ,
238+ // if true, will validate that the creator is authorized to create premints on the contract.
227239 checkSignature: true ,
228- // Collection information that this premint NFT will exist in once minted.
240+ // collection info of collection to create
229241 collection: {
230- contractAdmin: " 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 " ,
242+ contractAdmin: creatorAccount ,
231243 contractName: " Testing Contract" ,
232244 contractURI:
233245 " ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e" ,
234246 },
235- // WalletClient doing the signature
236- walletClient ,
237- // Token information, falls back to defaults set in DefaultMintArguments.
247+ // token info of token to create
238248 token: {
239249 tokenURI:
240250 " ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u" ,
241251 },
242252 });
243253
244- console .log (` created ZORA premint, link: ${premint .url } ` );
245- return premint ;
246- }
254+ const premintUid = createdPremint .uid ;
255+ const premintCollectionAddress = createdPremint .verifyingContract ;
256+
257+ return {
258+ // unique id of created premint, which can be used later to
259+ // update or delete the premint
260+ uid: premintUid ,
261+ tokenContract: premintCollectionAddress ,
262+ }
263+ }
247264```
248265
249- ### Updating a premint:
266+ ### Updating a token that was created for free (before it was brought onchain):
267+
268+ Before a token that was created for free 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.):
250269
251270``` ts
252- import { PremintAPI } from " @zoralabs/premint -sdk" ;
253- import type { Address , WalletClient } from " viem" ;
271+ import {createPremintClient } from " @zoralabs/protocol -sdk" ;
272+ import type {Address , PublicClient , WalletClient } from " viem" ;
254273
255- async function updatePremint (walletClient : WalletClient ) {
274+ async function updateCreatedForFreeToken (walletClient : WalletClient , premintUid : number ) {
256275 // Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently).
257- const premintAPI = createPremintAPI ( walletClient .chain );
276+ const premintClient = createPremintClient ({ chain: walletClient .chain ! } );
258277
259- // Create premint
260- const premint = await premintAPI .updatePremint ({
261- // Extra step to check the signature on-chain before attempting to sign
278+ // sign a message to update the created for free token, and store the update
279+ await premintClient .updatePremint ({
262280 collection: " 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ,
263- uid: 23 ,
281+ uid: premintUid ,
264282 // WalletClient doing the signature
265283 walletClient ,
266284 // Token information, falls back to defaults set in DefaultMintArguments.
@@ -269,73 +287,72 @@ async function updatePremint(walletClient: WalletClient) {
269287 " ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u" ,
270288 },
271289 });
272-
273- console .log (` updated ZORA premint, link: ${premint .url } ` );
274- return premint ;
275290}
276291```
277292
278- ### Deleting a premint:
293+ ### Deleting a token that was created for free (before it was brought onchain):
294+
295+ Before a token that was created for free is brought onchain, it can be deleted by the original creator of that token, by having that creator sign a message indicating the deletion:
279296
280297``` ts
281- import { PremintAPI } from " @zoralabs/premint -sdk" ;
282- import type { Address , WalletClient } from " viem" ;
298+ import {createPremintClient } from " @zoralabs/protocol -sdk" ;
299+ import type {Address , PublicClient , WalletClient } from " viem" ;
283300
284- async function deletePremint(walletClient : WalletClient ) {
285- // Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently).
286- const premintAPI = createPremintClient ({ chain: walletClient .chain });
301+ async function deleteCreatedForFreeToken(walletClient : WalletClient ) {
302+ const premintClient = createPremintClient ({ chain: walletClient .chain ! });
287303
288- // Create premint
289- const premint = await premintAPI .deletePremint ({
304+ // sign a message to delete the premint, and store the deletion
305+ await premintClient .deletePremint ({
290306 // Extra step to check the signature on-chain before attempting to sign
291307 collection: " 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ,
292308 uid: 23 ,
293309 // WalletClient doing the signature
294310 walletClient ,
295311 });
296-
297- console .log (` updated ZORA premint, link: ${premint .url } ` );
298- return premint ;
299312}
300313```
301314
302- ### Executing a premint :
315+ ### Minting a token that was created for free (and bringing it onchain) :
303316
304317``` ts
305- import { PremintAPI } from " @zoralabs/premint -sdk" ;
306- import type { Address , WalletClient } from " viem" ;
318+ import {createPremintClient } from " @zoralabs/protocol -sdk" ;
319+ import type {Address , PublicClient , WalletClient } from " viem" ;
307320
308- async function executePremint (
321+ async function mintCreatedForFreeToken (
309322 walletClient : WalletClient ,
310- premintAddress : Address ,
311- premintUID : number ,
323+ publicClient : PublicClient ,
324+ minterAccount : Address ,
312325) {
313- const premintAPI = createPremintClient ({ chain: walletClient .chain });
314-
315- return await premintAPI .executePremintWithWallet ({
316- data: premintAPI .getPremintData (premintAddress , premintUID ),
317- walletClient ,
326+ const premintClient = createPremintClient ({ chain: walletClient .chain ! });
327+
328+ const simulateContractParameters = await premintClient .makeMintParameters ({
329+ account: minterAccount ,
330+ data: await premintClient .getPremintData ({
331+ address: " 0xf8dA7f53c283d898818af7FB9d98103F559bDac2" ,
332+ uid: 3 ,
333+ }),
318334 mintArguments: {
319335 quantityToMint: 1 ,
336+ mintComment: " " ,
320337 },
321338 });
322- }
323- ```
324339
325- ### Deleting a premint:
340+ // simulate the transaction and get any validation errors
341+ const { request } = await publicClient .simulateContract (simulateContractParameters );
326342
327- ``` ts
328- import {PremintAPI } from ' @zoralabs/premint-sdk' ;
329- import type {Address , WalletClient } from ' viem' ;
343+ // submit the transaction to the network
344+ const txHash = await walletClient .writeContract (request );
330345
331- async function deletePremint( walletClient : WalletClient , collection : Address , uid : number ) {
332- const premintAPI = createPremintClient ({chain: walletClient . chain });
346+ // wait for the transaction to be complete
347+ const receipt = await publicClient . waitForTransactionReceipt ({hash: txHash });
333348
334- return await premintAPI .deletePremint ({
335- walletClient ,
336- uid ,
337- collection
338- });
339- }
349+ const { urls } = await premintClient .getDataFromPremintReceipt (receipt );
340350
341- ```
351+ // block explorer url:
352+ console .log (urls .explorer );
353+ // collect url:
354+ console .log (urls .zoraCollect );
355+ // manage url:
356+ console .log (urls .zoraManage );
357+ }
358+ ```
0 commit comments