From d066267486d8b76b8c74ff07c1c565e0be69c600 Mon Sep 17 00:00:00 2001 From: Jarrod Watts Date: Mon, 18 Jul 2022 17:21:53 +1000 Subject: [PATCH 1/2] Fix pack snippets --- src/contracts/pack.ts | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/contracts/pack.ts b/src/contracts/pack.ts index 9a92e965b..3aad0ce52 100644 --- a/src/contracts/pack.ts +++ b/src/contracts/pack.ts @@ -268,6 +268,46 @@ export class Pack extends Erc1155 { * @remarks See {@link Pack.createTo} * * @param metadataWithRewards - the metadata and rewards to include in the pack + * @example + * ```javascript + * const pack = { + * // The metadata for the pack NFT itself + * packMetadata: { + * name: "My Pack", + * description: "This is a new pack", + * image: "ipfs://...", + * }, + * // ERC20 rewards to be included in the pack + * erc20Rewards: [ + * { + * assetContract: "0x...", + * quantityPerReward: 5, + * quantity: 100, + * totalRewards: 20, + * } + * ], + * // ERC721 rewards to be included in the pack + * erc721Rewards: [ + * { + * assetContract: "0x...", + * tokenId: 0, + * } + * ], + * // ERC1155 rewards to be included in the pack + * erc1155Rewards: [ + * { + * assetContract: "0x...", + * tokenId: 0, + * quantityPerReward: 1, + * totalRewards: 100, + * } + * ], + * openStartTime: new Date(), // the date that packs can start to be opened, defaults to now + * rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1 + * } + * + * const tx = await contract.create(pack); + * ``` */ public async create(metadataWithRewards: PackMetadataInput) { const signerAddress = await this.contractWrapper.getSignerAddress(); @@ -294,7 +334,9 @@ export class Pack extends Erc1155 { * erc20Rewards: [ * { * assetContract: "0x...", + * quantityPerReward: 5, * quantity: 100, + * totalRewards: 20, * } * ], * // ERC721 rewards to be included in the pack @@ -309,7 +351,8 @@ export class Pack extends Erc1155 { * { * assetContract: "0x...", * tokenId: 0, - * quantity: 100, + * quantityPerReward: 1, + * totalRewards: 100, * } * ], * openStartTime: new Date(), // the date that packs can start to be opened, defaults to now From f110f75d2beefcc02447ae5587e87615c0c6a065 Mon Sep 17 00:00:00 2001 From: Jarrod Watts Date: Mon, 18 Jul 2022 17:23:18 +1000 Subject: [PATCH 2/2] Fix pack snippets build --- docs/sdk.pack.create.md | 43 +++++++++++++++++++++++++++++++++++++++ docs/sdk.pack.createto.md | 5 ++++- docs/snippets.json | 11 +++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/docs/sdk.pack.create.md b/docs/sdk.pack.create.md index 3b01784d3..deedda9e3 100644 --- a/docs/sdk.pack.create.md +++ b/docs/sdk.pack.create.md @@ -38,3 +38,46 @@ Promise<[TransactionResultWithId](./sdk.transactionresultwithid.md)&l See [Pack.createTo()](./sdk.pack.createto.md) +## Example + + +```javascript +const pack = { + // The metadata for the pack NFT itself + packMetadata: { + name: "My Pack", + description: "This is a new pack", + image: "ipfs://...", + }, + // ERC20 rewards to be included in the pack + erc20Rewards: [ + { + assetContract: "0x...", + quantityPerReward: 5, + quantity: 100, + totalRewards: 20, + } + ], + // ERC721 rewards to be included in the pack + erc721Rewards: [ + { + assetContract: "0x...", + tokenId: 0, + } + ], + // ERC1155 rewards to be included in the pack + erc1155Rewards: [ + { + assetContract: "0x...", + tokenId: 0, + quantityPerReward: 1, + totalRewards: 100, + } + ], + openStartTime: new Date(), // the date that packs can start to be opened, defaults to now + rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1 +} + +const tx = await contract.create(pack); +``` + diff --git a/docs/sdk.pack.createto.md b/docs/sdk.pack.createto.md index 2f4118267..6b919cc83 100644 --- a/docs/sdk.pack.createto.md +++ b/docs/sdk.pack.createto.md @@ -42,7 +42,9 @@ const pack = { erc20Rewards: [ { assetContract: "0x...", + quantityPerReward: 5, quantity: 100, + totalRewards: 20, } ], // ERC721 rewards to be included in the pack @@ -57,7 +59,8 @@ const pack = { { assetContract: "0x...", tokenId: 0, - quantity: 100, + quantityPerReward: 1, + totalRewards: 100, } ], openStartTime: new Date(), // the date that packs can start to be opened, defaults to now diff --git a/docs/snippets.json b/docs/snippets.json index a0a5f8087..920690d16 100644 --- a/docs/snippets.json +++ b/docs/snippets.json @@ -1221,12 +1221,21 @@ "javascript": "import { ThirdwebSDK } from \"@thirdweb-dev/sdk\";\n\nconst sdk = new ThirdwebSDK(\"{{chainName}}\");\nconst contract = sdk.getPack(\"{{contract_address}}\");" }, "methods": [ + { + "name": "create", + "summary": "Create Pack\n\n", + "remarks": "\n\nSee {@link Pack.createTo}\n\n", + "examples": { + "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);" + }, + "reference": "https://docs.thirdweb.com/typescript/sdk.Pack.create" + }, { "name": "createTo", "summary": "Create Pack To Wallet\n\n", "remarks": "\n\nCreate a new pack with the given metadata and rewards and mint it to the specified address.\n\n", "examples": { - "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);" + "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);" }, "reference": "https://docs.thirdweb.com/typescript/sdk.Pack.createTo" },