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

Jw/pack snipps #520

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/sdk.pack.create.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,46 @@ Promise&lt;[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);
```

5 changes: 4 additions & 1 deletion docs/sdk.pack.createto.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const pack = {
erc20Rewards: [
{
assetContract: "0x...",
quantityPerReward: 5,
quantity: 100,
totalRewards: 20,
}
],
// ERC721 rewards to be included in the pack
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion docs/snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
45 changes: 44 additions & 1 deletion src/contracts/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,46 @@ export class Pack extends Erc1155<PackContract> {
* @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();
Expand All @@ -294,7 +334,9 @@ export class Pack extends Erc1155<PackContract> {
* erc20Rewards: [
* {
* assetContract: "0x...",
* quantityPerReward: 5,
* quantity: 100,
* totalRewards: 20,
* }
* ],
* // ERC721 rewards to be included in the pack
Expand All @@ -309,7 +351,8 @@ export class Pack extends Erc1155<PackContract> {
* {
* 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
Expand Down