@zoralabs/protocol-sdk 0.9.1 → 0.9.2

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.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +6 -0
  3. package/dist/anvil.d.ts.map +1 -1
  4. package/dist/apis/http-api-base.d.ts +1 -1
  5. package/dist/apis/http-api-base.d.ts.map +1 -1
  6. package/dist/apis/subgraph-querier.d.ts +6 -0
  7. package/dist/apis/subgraph-querier.d.ts.map +1 -1
  8. package/dist/create/1155-create-helper.d.ts +4 -1
  9. package/dist/create/1155-create-helper.d.ts.map +1 -1
  10. package/dist/create/contract-getter.d.ts +30 -0
  11. package/dist/create/contract-getter.d.ts.map +1 -0
  12. package/dist/create/contract-setup.d.ts +4 -8
  13. package/dist/create/contract-setup.d.ts.map +1 -1
  14. package/dist/create/mint-from-create.d.ts +3 -3
  15. package/dist/create/mint-from-create.d.ts.map +1 -1
  16. package/dist/create/subgraph-queries.d.ts +13 -0
  17. package/dist/create/subgraph-queries.d.ts.map +1 -0
  18. package/dist/index.cjs +176 -97
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.js +155 -76
  21. package/dist/index.js.map +1 -1
  22. package/dist/mint/subgraph-mint-getter.d.ts +2 -2
  23. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  24. package/dist/mint/subgraph-queries.d.ts +1 -5
  25. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  26. package/dist/retries.d.ts +7 -0
  27. package/dist/retries.d.ts.map +1 -0
  28. package/dist/sdk.d.ts +2 -0
  29. package/dist/sdk.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/apis/http-api-base.ts +12 -20
  32. package/src/apis/subgraph-querier.ts +7 -0
  33. package/src/create/1155-create-helper.test.ts +22 -1
  34. package/src/create/1155-create-helper.ts +18 -9
  35. package/src/create/contract-getter.ts +90 -0
  36. package/src/create/contract-setup.ts +17 -46
  37. package/src/create/mint-from-create.ts +7 -15
  38. package/src/create/subgraph-queries.ts +35 -0
  39. package/src/mint/subgraph-mint-getter.ts +5 -2
  40. package/src/mint/subgraph-queries.ts +1 -7
  41. package/src/retries.ts +49 -0
  42. package/src/sdk.ts +8 -0
  43. package/test-integration/create-multiple-tokens-on-contract.ts +104 -0
package/src/sdk.ts CHANGED
@@ -8,6 +8,10 @@ import { ClientConfig } from "./utils";
8
8
  import { IPremintAPI, PremintAPIClient } from "./premint/premint-api-client";
9
9
  import { SubgraphMintGetter } from "./mint/subgraph-mint-getter";
10
10
  import { IOnchainMintGetter } from "./mint/types";
11
+ import {
12
+ IContractGetter,
13
+ SubgraphContractGetter,
14
+ } from "./create/contract-getter";
11
15
 
12
16
  export type CreatorClient = {
13
17
  createPremint: PremintClient["createPremint"];
@@ -29,6 +33,7 @@ export type CollectorClient = {
29
33
  export type CreatorClientConfig = ClientConfig & {
30
34
  /** API for submitting and getting premints. Defaults to the Zora Premint API */
31
35
  premintApi?: IPremintAPI;
36
+ contractGetter?: IContractGetter;
32
37
  };
33
38
 
34
39
  /**
@@ -50,6 +55,9 @@ export function createCreatorClient(
50
55
  const create1155CreatorClient = new Create1155Client({
51
56
  chainId: clientConfig.chainId,
52
57
  publicClient: clientConfig.publicClient,
58
+ contractGetter:
59
+ clientConfig.contractGetter ||
60
+ new SubgraphContractGetter(clientConfig.chainId),
53
61
  });
54
62
 
55
63
  return {
@@ -0,0 +1,104 @@
1
+ import { createCreatorClient } from "src";
2
+ import {
3
+ Address,
4
+ Chain,
5
+ LocalAccount,
6
+ createPublicClient,
7
+ createWalletClient,
8
+ http,
9
+ } from "viem";
10
+ import { privateKeyToAccount } from "viem/accounts";
11
+ import { zoraSepolia } from "viem/chains";
12
+
13
+ const publicClient = createPublicClient({
14
+ chain: zoraSepolia as Chain,
15
+ transport: http(),
16
+ });
17
+
18
+ const walletClient = createWalletClient({
19
+ chain: zoraSepolia,
20
+ transport: http(),
21
+ });
22
+
23
+ const creatorClient = createCreatorClient({
24
+ chainId: zoraSepolia.id,
25
+ publicClient,
26
+ });
27
+
28
+ export const createMultipleTokensOnContract = async ({
29
+ creatorAccount,
30
+ }: {
31
+ creatorAccount: LocalAccount;
32
+ }) => {
33
+ console.log({ address: creatorAccount.address });
34
+ const { contractAddress, parameters } = await creatorClient.create1155({
35
+ account: creatorAccount.address,
36
+ contract: {
37
+ name: "testContractD",
38
+ uri: "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
39
+ },
40
+ token: {
41
+ tokenMetadataURI:
42
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
43
+ },
44
+ });
45
+ console.log("creating contract and token");
46
+
47
+ const { request: requestA } = await publicClient.simulateContract(parameters);
48
+
49
+ const hashA = await walletClient.writeContract({
50
+ ...requestA,
51
+ account: creatorAccount,
52
+ });
53
+
54
+ const receiptA = await publicClient.waitForTransactionReceipt({
55
+ hash: hashA,
56
+ });
57
+
58
+ if (receiptA.status !== "success") {
59
+ throw new Error("create new contract failed");
60
+ }
61
+
62
+ console.log("creating new token on contract");
63
+
64
+ const { parameters: parametersB } =
65
+ await creatorClient.create1155OnExistingContract({
66
+ account: creatorAccount.address,
67
+ contractAddress,
68
+ token: {
69
+ tokenMetadataURI:
70
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
71
+ },
72
+ });
73
+
74
+ const { request: requestB } =
75
+ await publicClient.simulateContract(parametersB);
76
+
77
+ const hashB = await walletClient.writeContract({
78
+ ...requestB,
79
+ account: creatorAccount,
80
+ });
81
+
82
+ const receiptB = await publicClient.waitForTransactionReceipt({
83
+ hash: hashB,
84
+ });
85
+
86
+ if (receiptB.status !== "success") {
87
+ throw new Error("create token on contract failed");
88
+ }
89
+
90
+ console.log("created multiple tokens on contract");
91
+ };
92
+
93
+ const setupTestContracts = async () => {
94
+ const creatorAccount = privateKeyToAccount(
95
+ process.env.VITE_PRIVATE_KEY! as Address,
96
+ );
97
+
98
+ // create 2 premints on a contract
99
+ await createMultipleTokensOnContract({
100
+ creatorAccount,
101
+ });
102
+ };
103
+
104
+ setupTestContracts();