@medialane/sdk 0.6.8 → 0.7.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/README.md CHANGED
@@ -64,10 +64,10 @@ yarn add @medialane/sdk starknet
64
64
  import { MedialaneClient } from "@medialane/sdk";
65
65
 
66
66
  const client = new MedialaneClient({
67
- network: "mainnet", // "mainnet" | "sepolia"
68
- rpcUrl: "https://rpc.starknet.lava.build", // optional; defaults to Lava
69
- backendUrl: "https://medialane-backend-production.up.railway.app", // required for .api methods
70
- apiKey: "ml_live_...", // from Medialane Portal
67
+ network: "mainnet", // mainnet only
68
+ rpcUrl: "https://rpc.starknet.lava.build", // optional; defaults to Lava
69
+ backendUrl: "https://medialane-backend-production.up.railway.app", // required for .api methods
70
+ apiKey: "ml_live_...", // from Medialane Portal
71
71
  });
72
72
  ```
73
73
 
@@ -77,7 +77,11 @@ const client = new MedialaneClient({
77
77
 
78
78
  All methods require a `starknet.js` `AccountInterface`. Nonce management, SNIP-12 signing, and `waitForTransaction` are handled automatically.
79
79
 
80
- ### Create a Listing
80
+ Two marketplace modules are available:
81
+ - `client.marketplace` — ERC-721 marketplace (`Medialane` contract)
82
+ - `client.marketplace1155` — ERC-1155 marketplace (`Medialane1155` contract, deployed 2026-04-15)
83
+
84
+ ### Create a Listing (ERC-721)
81
85
 
82
86
  ```typescript
83
87
  import { Account } from "starknet";
@@ -153,6 +157,59 @@ const result = await client.marketplace.createCollection(account, {
153
157
 
154
158
  ---
155
159
 
160
+ ## ERC-1155 Marketplace (Medialane1155)
161
+
162
+ For IP assets from ERC-1155 collections (e.g. IP-Programmable-ERC1155-Collections). Contract: `0x042005e9b85536072bfa260b95aa6aaef07f48e622031657384d2375195d7123`.
163
+
164
+ ### Create an ERC-1155 Listing
165
+
166
+ ```typescript
167
+ const result = await client.marketplace1155.createListing(account, {
168
+ nftContract: "0x...", // ERC-1155 collection address
169
+ tokenId: "1",
170
+ amount: "10", // number of tokens to sell
171
+ pricePerUnit: "1", // human-readable price per token (e.g. "1" USDC)
172
+ currency: "USDC",
173
+ durationSeconds: 86400 * 30,
174
+ });
175
+ ```
176
+
177
+ `set_approval_for_all` is granted automatically if not already in place.
178
+
179
+ ### Fulfill an ERC-1155 Order
180
+
181
+ ```typescript
182
+ // Fetch order details first to get paymentToken and totalPrice
183
+ const details = await client.api.getOrder(orderHash);
184
+
185
+ const result = await client.marketplace1155.fulfillOrder(account, {
186
+ orderHash: "0x...",
187
+ paymentToken: "0x033068...", // from order details
188
+ totalPrice: "10000000", // pricePerUnit × amount in raw token units
189
+ });
190
+ ```
191
+
192
+ ERC-2981 royalties are automatically deducted by the contract at fulfillment.
193
+
194
+ ### Cancel an ERC-1155 Order
195
+
196
+ ```typescript
197
+ const result = await client.marketplace1155.cancelOrder(account, {
198
+ orderHash: "0x...",
199
+ });
200
+ ```
201
+
202
+ ### SNIP-12 Typed Data Builders (ChipiPay / custom flows)
203
+
204
+ ```typescript
205
+ import { build1155OrderTypedData, build1155FulfillmentTypedData, build1155CancellationTypedData } from "@medialane/sdk";
206
+ import { constants } from "starknet";
207
+
208
+ const typedData = build1155OrderTypedData(orderParams, constants.StarknetChainId.SN_MAIN);
209
+ ```
210
+
211
+ ---
212
+
156
213
  ## REST API
157
214
 
158
215
  ### Query Orders
package/dist/index.cjs CHANGED
@@ -49,6 +49,8 @@ var SUPPORTED_NETWORKS = ["mainnet"];
49
49
  var DEFAULT_RPC_URL = "https://rpc.starknet.lava.build";
50
50
  var POP_COLLECTION_CLASS_HASH_MAINNET = "0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f";
51
51
  var DROP_COLLECTION_CLASS_HASH_MAINNET = "0x00092e72cdb63067521e803aaf7d4101c3e3ce026ae6bc045ec4228027e58282";
52
+ var ERC1155_FACTORY_CONTRACT_MAINNET = "0x0459a9a3c04be5d884a038744f977dff019897264d4a281f9e0f87af417b3bec";
53
+ var ERC1155_COLLECTION_CLASS_HASH_MAINNET = "0x02da5e81be7a1ca493b9441522c450f8ff4c54b14ec16a0c2349f5e6e6fdc5d7";
52
54
 
53
55
  // src/config.ts
54
56
  var MedialaneConfigSchema = zod.z.object({
@@ -1720,6 +1722,126 @@ var Medialane1155ABI = [
1720
1722
  ]
1721
1723
  }
1722
1724
  ];
1725
+ var IPCollection1155FactoryABI = [
1726
+ {
1727
+ type: "function",
1728
+ name: "collection_class_hash",
1729
+ inputs: [],
1730
+ outputs: [{ type: "core::starknet::class_hash::ClassHash" }],
1731
+ state_mutability: "view"
1732
+ },
1733
+ {
1734
+ type: "function",
1735
+ name: "deploy_collection",
1736
+ inputs: [
1737
+ { name: "name", type: "core::byte_array::ByteArray" },
1738
+ { name: "symbol", type: "core::byte_array::ByteArray" }
1739
+ ],
1740
+ outputs: [{ type: "core::starknet::contract_address::ContractAddress" }],
1741
+ state_mutability: "external"
1742
+ },
1743
+ {
1744
+ type: "function",
1745
+ name: "owner",
1746
+ inputs: [],
1747
+ outputs: [{ type: "core::starknet::contract_address::ContractAddress" }],
1748
+ state_mutability: "view"
1749
+ }
1750
+ ];
1751
+ var IPCollection1155ABI = [
1752
+ {
1753
+ type: "function",
1754
+ name: "mint_item",
1755
+ inputs: [
1756
+ { name: "to", type: "core::starknet::contract_address::ContractAddress" },
1757
+ { name: "token_id", type: "core::integer::u256" },
1758
+ { name: "value", type: "core::integer::u256" },
1759
+ { name: "token_uri", type: "core::byte_array::ByteArray" }
1760
+ ],
1761
+ outputs: [],
1762
+ state_mutability: "external"
1763
+ },
1764
+ {
1765
+ type: "function",
1766
+ name: "batch_mint_item",
1767
+ inputs: [
1768
+ { name: "to", type: "core::starknet::contract_address::ContractAddress" },
1769
+ { name: "token_ids", type: "core::array::Span::<core::integer::u256>" },
1770
+ { name: "values", type: "core::array::Span::<core::integer::u256>" },
1771
+ { name: "token_uris", type: "core::array::Array::<core::byte_array::ByteArray>" }
1772
+ ],
1773
+ outputs: [],
1774
+ state_mutability: "external"
1775
+ },
1776
+ {
1777
+ type: "function",
1778
+ name: "uri",
1779
+ inputs: [{ name: "token_id", type: "core::integer::u256" }],
1780
+ outputs: [{ type: "core::byte_array::ByteArray" }],
1781
+ state_mutability: "view"
1782
+ },
1783
+ {
1784
+ type: "function",
1785
+ name: "get_collection_creator",
1786
+ inputs: [],
1787
+ outputs: [{ type: "core::starknet::contract_address::ContractAddress" }],
1788
+ state_mutability: "view"
1789
+ },
1790
+ {
1791
+ type: "function",
1792
+ name: "get_token_creator",
1793
+ inputs: [{ name: "token_id", type: "core::integer::u256" }],
1794
+ outputs: [{ type: "core::starknet::contract_address::ContractAddress" }],
1795
+ state_mutability: "view"
1796
+ },
1797
+ {
1798
+ type: "function",
1799
+ name: "owner",
1800
+ inputs: [],
1801
+ outputs: [{ type: "core::starknet::contract_address::ContractAddress" }],
1802
+ state_mutability: "view"
1803
+ },
1804
+ {
1805
+ type: "function",
1806
+ name: "balance_of",
1807
+ inputs: [
1808
+ { name: "account", type: "core::starknet::contract_address::ContractAddress" },
1809
+ { name: "token_id", type: "core::integer::u256" }
1810
+ ],
1811
+ outputs: [{ type: "core::integer::u256" }],
1812
+ state_mutability: "view"
1813
+ },
1814
+ {
1815
+ type: "function",
1816
+ name: "set_approval_for_all",
1817
+ inputs: [
1818
+ { name: "operator", type: "core::starknet::contract_address::ContractAddress" },
1819
+ { name: "approved", type: "core::bool" }
1820
+ ],
1821
+ outputs: [],
1822
+ state_mutability: "external"
1823
+ },
1824
+ {
1825
+ type: "function",
1826
+ name: "is_approved_for_all",
1827
+ inputs: [
1828
+ { name: "owner", type: "core::starknet::contract_address::ContractAddress" },
1829
+ { name: "operator", type: "core::starknet::contract_address::ContractAddress" }
1830
+ ],
1831
+ outputs: [{ type: "core::bool" }],
1832
+ state_mutability: "view"
1833
+ },
1834
+ {
1835
+ type: "function",
1836
+ name: "set_royalty",
1837
+ inputs: [
1838
+ { name: "receiver", type: "core::starknet::contract_address::ContractAddress" },
1839
+ { name: "fee_numerator", type: "core::integer::u128" }
1840
+ ],
1841
+ outputs: [],
1842
+ state_mutability: "external"
1843
+ }
1844
+ ];
1723
1845
 
1724
1846
  // src/utils/bigint.ts
1725
1847
  function stringifyBigInts(obj) {
@@ -3169,6 +3291,99 @@ var MedialaneClient = class {
3169
3291
 
3170
3292
  // src/types/api.ts
3171
3293
  var OPEN_LICENSES = ["CC0", "CC BY", "CC BY-SA", "CC BY-NC"];
3294
+ var ERC1155CollectionService = class {
3295
+ constructor(_config) {
3296
+ this.factoryAddress = ERC1155_FACTORY_CONTRACT_MAINNET;
3297
+ }
3298
+ _factory(account) {
3299
+ return new starknet.Contract(
3300
+ IPCollection1155FactoryABI,
3301
+ normalizeAddress(this.factoryAddress),
3302
+ account
3303
+ );
3304
+ }
3305
+ _collection(address, account) {
3306
+ return new starknet.Contract(
3307
+ IPCollection1155ABI,
3308
+ normalizeAddress(address),
3309
+ account
3310
+ );
3311
+ }
3312
+ /**
3313
+ * Deploy a new ERC-1155 IP collection.
3314
+ * Caller becomes the collection owner and can mint items.
3315
+ * Returns the transaction hash; the deployed collection address is emitted
3316
+ * in the `CollectionDeployed` event of the factory.
3317
+ */
3318
+ async deployCollection(account, params) {
3319
+ const factory = this._factory(account);
3320
+ const call = factory.populate("deploy_collection", [params.name, params.symbol]);
3321
+ const res = await account.execute([call]);
3322
+ return { txHash: res.transaction_hash };
3323
+ }
3324
+ /**
3325
+ * Mint a single token into an existing ERC-1155 collection.
3326
+ * Caller must be the collection owner.
3327
+ * The `tokenUri` is immutable — validated and stored on the first mint only.
3328
+ */
3329
+ async mintItem(account, params) {
3330
+ const collection = this._collection(params.collection, account);
3331
+ const call = collection.populate("mint_item", [
3332
+ params.to,
3333
+ BigInt(params.tokenId),
3334
+ BigInt(params.value),
3335
+ params.tokenUri
3336
+ ]);
3337
+ const res = await account.execute([call]);
3338
+ return { txHash: res.transaction_hash };
3339
+ }
3340
+ /**
3341
+ * Batch-mint multiple token IDs into an existing ERC-1155 collection.
3342
+ * All items go to the same `to` address.
3343
+ * Caller must be the collection owner.
3344
+ */
3345
+ async batchMintItem(account, params) {
3346
+ const collection = this._collection(params.collection, account);
3347
+ const tokenIds = params.items.map((i) => BigInt(i.tokenId));
3348
+ const values = params.items.map((i) => BigInt(i.value));
3349
+ const tokenUris = params.items.map((i) => i.tokenUri);
3350
+ const call = collection.populate("batch_mint_item", [
3351
+ params.to,
3352
+ tokenIds,
3353
+ values,
3354
+ tokenUris
3355
+ ]);
3356
+ const res = await account.execute([call]);
3357
+ return { txHash: res.transaction_hash };
3358
+ }
3359
+ /**
3360
+ * Set ERC-2981 royalties for the collection.
3361
+ * `feeNumerator` is out of 10 000 (e.g. 500 = 5%).
3362
+ * Caller must be the collection owner.
3363
+ */
3364
+ async setRoyalty(account, params) {
3365
+ const collection = this._collection(params.collection, account);
3366
+ const call = collection.populate("set_royalty", [
3367
+ params.receiver,
3368
+ BigInt(params.feeNumerator)
3369
+ ]);
3370
+ const res = await account.execute([call]);
3371
+ return { txHash: res.transaction_hash };
3372
+ }
3373
+ /**
3374
+ * Approve the Medialane1155 marketplace (or any operator) to transfer
3375
+ * all tokens on behalf of `account`. Required before listing.
3376
+ */
3377
+ async setApprovalForAll(account, params) {
3378
+ const collection = this._collection(params.collection, account);
3379
+ const call = collection.populate("set_approval_for_all", [
3380
+ params.operator,
3381
+ params.approved
3382
+ ]);
3383
+ const res = await account.execute([call]);
3384
+ return { txHash: res.transaction_hash };
3385
+ }
3386
+ };
3172
3387
 
3173
3388
  exports.ApiClient = ApiClient;
3174
3389
  exports.COLLECTION_CONTRACT_MAINNET = COLLECTION_CONTRACT_MAINNET;
@@ -3179,6 +3394,11 @@ exports.DROP_FACTORY_CONTRACT_MAINNET = DROP_FACTORY_CONTRACT_MAINNET;
3179
3394
  exports.DropCollectionABI = DropCollectionABI;
3180
3395
  exports.DropFactoryABI = DropFactoryABI;
3181
3396
  exports.DropService = DropService;
3397
+ exports.ERC1155CollectionService = ERC1155CollectionService;
3398
+ exports.ERC1155_COLLECTION_CLASS_HASH_MAINNET = ERC1155_COLLECTION_CLASS_HASH_MAINNET;
3399
+ exports.ERC1155_FACTORY_CONTRACT_MAINNET = ERC1155_FACTORY_CONTRACT_MAINNET;
3400
+ exports.IPCollection1155ABI = IPCollection1155ABI;
3401
+ exports.IPCollection1155FactoryABI = IPCollection1155FactoryABI;
3182
3402
  exports.IPMarketplaceABI = IPMarketplaceABI;
3183
3403
  exports.MARKETPLACE_1155_CONTRACT_MAINNET = MARKETPLACE_1155_CONTRACT_MAINNET;
3184
3404
  exports.MARKETPLACE_CONTRACT_MAINNET = MARKETPLACE_CONTRACT_MAINNET;