Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 02f13c7

Browse files
authored
Jw/pack snipps (#520)
* Fix pack snippets * Fix pack snippets build
1 parent 7b69384 commit 02f13c7

File tree

4 files changed

+101
-3
lines changed

4 files changed

+101
-3
lines changed

docs/sdk.pack.create.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,46 @@ Promise&lt;[TransactionResultWithId](./sdk.transactionresultwithid.md)<!-- -->&l
3838

3939
See [Pack.createTo()](./sdk.pack.createto.md)
4040

41+
## Example
42+
43+
44+
```javascript
45+
const pack = {
46+
// The metadata for the pack NFT itself
47+
packMetadata: {
48+
name: "My Pack",
49+
description: "This is a new pack",
50+
image: "ipfs://...",
51+
},
52+
// ERC20 rewards to be included in the pack
53+
erc20Rewards: [
54+
{
55+
assetContract: "0x...",
56+
quantityPerReward: 5,
57+
quantity: 100,
58+
totalRewards: 20,
59+
}
60+
],
61+
// ERC721 rewards to be included in the pack
62+
erc721Rewards: [
63+
{
64+
assetContract: "0x...",
65+
tokenId: 0,
66+
}
67+
],
68+
// ERC1155 rewards to be included in the pack
69+
erc1155Rewards: [
70+
{
71+
assetContract: "0x...",
72+
tokenId: 0,
73+
quantityPerReward: 1,
74+
totalRewards: 100,
75+
}
76+
],
77+
openStartTime: new Date(), // the date that packs can start to be opened, defaults to now
78+
rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1
79+
}
80+
81+
const tx = await contract.create(pack);
82+
```
83+

docs/sdk.pack.createto.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ const pack = {
4242
erc20Rewards: [
4343
{
4444
assetContract: "0x...",
45+
quantityPerReward: 5,
4546
quantity: 100,
47+
totalRewards: 20,
4648
}
4749
],
4850
// ERC721 rewards to be included in the pack
@@ -57,7 +59,8 @@ const pack = {
5759
{
5860
assetContract: "0x...",
5961
tokenId: 0,
60-
quantity: 100,
62+
quantityPerReward: 1,
63+
totalRewards: 100,
6164
}
6265
],
6366
openStartTime: new Date(), // the date that packs can start to be opened, defaults to now

docs/snippets.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,12 +1221,21 @@
12211221
"javascript": "import { ThirdwebSDK } from \"@thirdweb-dev/sdk\";\n\nconst sdk = new ThirdwebSDK(\"{{chainName}}\");\nconst contract = sdk.getPack(\"{{contract_address}}\");"
12221222
},
12231223
"methods": [
1224+
{
1225+
"name": "create",
1226+
"summary": "Create Pack\n\n",
1227+
"remarks": "\n\nSee {@link Pack.createTo}\n\n",
1228+
"examples": {
1229+
"javascript": "const pack = {\n // The metadata for the pack NFT itself\n packMetadata: {\n name: \"My Pack\",\n description: \"This is a new pack\",\n image: \"ipfs://...\",\n },\n // ERC20 rewards to be included in the pack\n erc20Rewards: [\n {\n assetContract: \"0x...\",\n quantityPerReward: 5,\n quantity: 100,\n totalRewards: 20,\n }\n ],\n // ERC721 rewards to be included in the pack\n erc721Rewards: [\n {\n assetContract: \"0x...\",\n tokenId: 0,\n }\n ],\n // ERC1155 rewards to be included in the pack\n erc1155Rewards: [\n {\n assetContract: \"0x...\",\n tokenId: 0,\n quantityPerReward: 1,\n totalRewards: 100,\n }\n ],\n openStartTime: new Date(), // the date that packs can start to be opened, defaults to now\n rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1\n}\n\nconst tx = await contract.create(pack);"
1230+
},
1231+
"reference": "https://docs.thirdweb.com/typescript/sdk.Pack.create"
1232+
},
12241233
{
12251234
"name": "createTo",
12261235
"summary": "Create Pack To Wallet\n\n",
12271236
"remarks": "\n\nCreate a new pack with the given metadata and rewards and mint it to the specified address.\n\n",
12281237
"examples": {
1229-
"javascript": "const pack = {\n // The metadata for the pack NFT itself\n packMetadata: {\n name: \"My Pack\",\n description: \"This is a new pack\",\n image: \"ipfs://...\",\n },\n // ERC20 rewards to be included in the pack\n erc20Rewards: [\n {\n assetContract: \"0x...\",\n quantity: 100,\n }\n ],\n // ERC721 rewards to be included in the pack\n erc721Rewards: [\n {\n assetContract: \"0x...\",\n tokenId: 0,\n }\n ],\n // ERC1155 rewards to be included in the pack\n erc1155Rewards: [\n {\n assetContract: \"0x...\",\n tokenId: 0,\n quantity: 100,\n }\n ],\n openStartTime: new Date(), // the date that packs can start to be opened, defaults to now\n rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1\n}\n\nconst tx = await contract.createTo(\"0x...\", pack);"
1238+
"javascript": "const pack = {\n // The metadata for the pack NFT itself\n packMetadata: {\n name: \"My Pack\",\n description: \"This is a new pack\",\n image: \"ipfs://...\",\n },\n // ERC20 rewards to be included in the pack\n erc20Rewards: [\n {\n assetContract: \"0x...\",\n quantityPerReward: 5,\n quantity: 100,\n totalRewards: 20,\n }\n ],\n // ERC721 rewards to be included in the pack\n erc721Rewards: [\n {\n assetContract: \"0x...\",\n tokenId: 0,\n }\n ],\n // ERC1155 rewards to be included in the pack\n erc1155Rewards: [\n {\n assetContract: \"0x...\",\n tokenId: 0,\n quantityPerReward: 1,\n totalRewards: 100,\n }\n ],\n openStartTime: new Date(), // the date that packs can start to be opened, defaults to now\n rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1\n}\n\nconst tx = await contract.createTo(\"0x...\", pack);"
12301239
},
12311240
"reference": "https://docs.thirdweb.com/typescript/sdk.Pack.createTo"
12321241
},

src/contracts/pack.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,46 @@ export class Pack extends Erc1155<PackContract> {
268268
* @remarks See {@link Pack.createTo}
269269
*
270270
* @param metadataWithRewards - the metadata and rewards to include in the pack
271+
* @example
272+
* ```javascript
273+
* const pack = {
274+
* // The metadata for the pack NFT itself
275+
* packMetadata: {
276+
* name: "My Pack",
277+
* description: "This is a new pack",
278+
* image: "ipfs://...",
279+
* },
280+
* // ERC20 rewards to be included in the pack
281+
* erc20Rewards: [
282+
* {
283+
* assetContract: "0x...",
284+
* quantityPerReward: 5,
285+
* quantity: 100,
286+
* totalRewards: 20,
287+
* }
288+
* ],
289+
* // ERC721 rewards to be included in the pack
290+
* erc721Rewards: [
291+
* {
292+
* assetContract: "0x...",
293+
* tokenId: 0,
294+
* }
295+
* ],
296+
* // ERC1155 rewards to be included in the pack
297+
* erc1155Rewards: [
298+
* {
299+
* assetContract: "0x...",
300+
* tokenId: 0,
301+
* quantityPerReward: 1,
302+
* totalRewards: 100,
303+
* }
304+
* ],
305+
* openStartTime: new Date(), // the date that packs can start to be opened, defaults to now
306+
* rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1
307+
* }
308+
*
309+
* const tx = await contract.create(pack);
310+
* ```
271311
*/
272312
public async create(metadataWithRewards: PackMetadataInput) {
273313
const signerAddress = await this.contractWrapper.getSignerAddress();
@@ -294,7 +334,9 @@ export class Pack extends Erc1155<PackContract> {
294334
* erc20Rewards: [
295335
* {
296336
* assetContract: "0x...",
337+
* quantityPerReward: 5,
297338
* quantity: 100,
339+
* totalRewards: 20,
298340
* }
299341
* ],
300342
* // ERC721 rewards to be included in the pack
@@ -309,7 +351,8 @@ export class Pack extends Erc1155<PackContract> {
309351
* {
310352
* assetContract: "0x...",
311353
* tokenId: 0,
312-
* quantity: 100,
354+
* quantityPerReward: 1,
355+
* totalRewards: 100,
313356
* }
314357
* ],
315358
* openStartTime: new Date(), // the date that packs can start to be opened, defaults to now

0 commit comments

Comments
 (0)