Skip to content

Commit eb919ed

Browse files
authored
implement extensions for royalty, platformfee and primarysale (#2749)
1 parent 4d7ecc2 commit eb919ed

File tree

15 files changed

+211
-109
lines changed

15 files changed

+211
-109
lines changed

.changeset/selfish-peaches-carry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
- storage: `upload` now returns a single `uri` when a single file is passed to the `files` array.
6+
- extensions: added suport for `royalty`, `platformFee` and `primarySale` extensions

packages/thirdweb/src/exports/extensions/common.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,53 @@ export {
1616
type SetOwnerParams,
1717
} from "../../extensions/common/__generated__/IOwnable/write/setOwner.js";
1818

19+
export {
20+
setContractMetadata,
21+
type SetContractMetadataParams,
22+
} from "../../extensions/common/write/setContractMetadata.js";
23+
1924
// events
2025

2126
export {
2227
ownerUpdatedEvent,
2328
type OwnerUpdatedEventFilters,
2429
} from "../../extensions/common/__generated__/IOwnable/events/OwnerUpdated.js";
30+
31+
// --------------------------------------------------------
32+
// Royalty
33+
// --------------------------------------------------------
34+
// read
35+
export { getDefaultRoyaltyInfo } from "../../extensions/common/__generated__/IRoyalty/read/getDefaultRoyaltyInfo.js";
36+
export {
37+
getRoyaltyInfoForToken,
38+
type GetRoyaltyInfoForTokenParams,
39+
} from "../../extensions/common/__generated__/IRoyalty/read/getRoyaltyInfoForToken.js";
40+
41+
// write
42+
export {
43+
setDefaultRoyaltyInfo,
44+
type SetDefaultRoyaltyInfoParams,
45+
} from "../../extensions/common/__generated__/IRoyalty/write/setDefaultRoyaltyInfo.js";
46+
export {
47+
setRoyaltyInfoForToken,
48+
type SetRoyaltyInfoForTokenParams,
49+
} from "../../extensions/common/__generated__/IRoyalty/write/setRoyaltyInfoForToken.js";
50+
51+
// --------------------------------------------------------
52+
// Platform Fees
53+
// --------------------------------------------------------
54+
55+
export { getPlatformFeeInfo } from "../../extensions/common/__generated__/IPlatformFee/read/getPlatformFeeInfo.js";
56+
export {
57+
setPlatformFeeInfo,
58+
type SetPlatformFeeInfoParams,
59+
} from "../../extensions/common/__generated__/IPlatformFee/write/setPlatformFeeInfo.js";
60+
61+
// --------------------------------------------------------
62+
// Primary Sale
63+
// --------------------------------------------------------
64+
export { primarySaleRecipient } from "../../extensions/common/__generated__/IPrimarySale/read/primarySaleRecipient.js";
65+
export {
66+
setPrimarySaleRecipient,
67+
type SetPrimarySaleRecipientParams,
68+
} from "../../extensions/common/__generated__/IPrimarySale/write/setPrimarySaleRecipient.js";
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { upload } from "../../../storage/upload.js";
2+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
3+
import { setContractURI } from "../__generated__/IContractMetadata/write/setContractURI.js";
4+
5+
export type SetContractMetadataParams = Record<string, unknown>;
6+
7+
/**
8+
* Sets the metadata for a contract.
9+
*
10+
* @param options - The options for setting the contract metadata.
11+
* @returns - The prepared transaction to set the contract metadata.
12+
* @extension COMMON
13+
* @example
14+
* ```ts
15+
* import { setContractMetadata } from '@thirdweb/extensions/common';
16+
*
17+
* const transaction = setContractMetadata({
18+
* contract,
19+
* name: 'My NFT',
20+
* symbol: 'NFT',
21+
* });
22+
*
23+
* // Send the transaction
24+
* await sendTransaction({
25+
* transaction,
26+
* account,
27+
* });
28+
* ```
29+
*/
30+
export function setContractMetadata({
31+
contract,
32+
...restParams
33+
}: BaseTransactionOptions<SetContractMetadataParams>) {
34+
return setContractURI({
35+
contract,
36+
asyncParams: async () => {
37+
const uri = await upload({
38+
client: contract.client,
39+
files: [restParams],
40+
});
41+
42+
return {
43+
uri,
44+
};
45+
},
46+
});
47+
}

packages/thirdweb/src/extensions/erc1155/write/mintTo.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ export function mintTo(options: BaseTransactionOptions<MintToParams>) {
4848

4949
// load the upload code if we need it
5050
const { upload } = await import("../../../storage/upload.js");
51-
tokenUri = (
52-
await upload({
53-
client: options.contract.client,
54-
files: [options.nft],
55-
})
56-
)[0] as string;
51+
tokenUri = await upload({
52+
client: options.contract.client,
53+
files: [options.nft],
54+
});
5755
}
5856
return {
5957
to: options.to,

packages/thirdweb/src/extensions/erc721/write/mintTo.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ export function mintTo(options: BaseTransactionOptions<MintToParams>) {
4545

4646
// load the upload code if we need it
4747
const { upload } = await import("../../../storage/upload.js");
48-
tokenUri = (
49-
await upload({
50-
client: options.contract.client,
51-
files: [options.nft],
52-
})
53-
)[0] as string;
48+
tokenUri = await upload({
49+
client: options.contract.client,
50+
files: [options.nft],
51+
});
5452
}
5553
return {
5654
to: options.to,

packages/thirdweb/src/extensions/erc721/write/setSharedMetadata.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ export function setSharedMetadata(
2626
return options.nft.image;
2727
}
2828
const { upload } = await import("../../../storage/upload.js");
29-
return (
30-
await upload({
31-
client: options.contract.client,
32-
files: [options.nft.image],
33-
})
34-
)[0] as string;
29+
return await upload({
30+
client: options.contract.client,
31+
files: [options.nft.image],
32+
});
3533
})(),
3634
// animation URI resolution
3735
(async () => {
@@ -42,12 +40,10 @@ export function setSharedMetadata(
4240
return options.nft.animation_url;
4341
}
4442
const { upload } = await import("../../../storage/upload.js");
45-
return (
46-
await upload({
47-
client: options.contract.client,
48-
files: [options.nft.animation_url],
49-
})
50-
)[0] as string;
43+
return await upload({
44+
client: options.contract.client,
45+
files: [options.nft.animation_url],
46+
});
5147
})(),
5248
];
5349

packages/thirdweb/src/extensions/erc721/write/sigMint.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ export async function generateMintSignature(
8585

8686
let uri: string;
8787
if (typeof mintRequest.metadata === "object") {
88-
uri = (
89-
await upload({
90-
client: options.contract.client,
91-
files: [mintRequest.metadata],
92-
})
93-
)[0] as string;
88+
uri = await upload({
89+
client: options.contract.client,
90+
files: [mintRequest.metadata],
91+
});
9492
} else {
9593
uri = mintRequest.metadata;
9694
}

packages/thirdweb/src/extensions/prebuilts/deploy-erc1155.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,21 @@ async function getInitializeTransaction(options: {
9696
options;
9797
const contractURI =
9898
options.params.contractURI ||
99-
(
100-
await upload({
101-
client,
102-
files: [
103-
{
104-
name: params.name,
105-
description: params.description,
106-
symbol: params.symbol,
107-
image: params.image,
108-
external_link: params.external_link,
109-
social_urls: params.social_urls,
110-
seller_fee_basis_points: params.royaltyBps,
111-
fee_recipient: params.royaltyRecipient,
112-
},
113-
],
114-
})
115-
)[0] ||
99+
(await upload({
100+
client,
101+
files: [
102+
{
103+
name: params.name,
104+
description: params.description,
105+
symbol: params.symbol,
106+
image: params.image,
107+
external_link: params.external_link,
108+
social_urls: params.social_urls,
109+
seller_fee_basis_points: params.royaltyBps,
110+
fee_recipient: params.royaltyRecipient,
111+
},
112+
],
113+
})) ||
116114
"";
117115
switch (type) {
118116
case "DropERC1155":

packages/thirdweb/src/extensions/prebuilts/deploy-erc20.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,19 @@ async function getInitializeTransaction(options: {
9292
options;
9393
const contractURI =
9494
options.params.contractURI ||
95-
(
96-
await upload({
97-
client,
98-
files: [
99-
{
100-
name: params.name,
101-
description: params.description,
102-
symbol: params.symbol,
103-
image: params.image,
104-
external_link: params.external_link,
105-
social_urls: params.social_urls,
106-
},
107-
],
108-
})
109-
)[0] ||
95+
(await upload({
96+
client,
97+
files: [
98+
{
99+
name: params.name,
100+
description: params.description,
101+
symbol: params.symbol,
102+
image: params.image,
103+
external_link: params.external_link,
104+
social_urls: params.social_urls,
105+
},
106+
],
107+
})) ||
110108
"";
111109
switch (type) {
112110
case "DropERC20":

packages/thirdweb/src/extensions/prebuilts/deploy-erc721.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,21 @@ async function getInitializeTransaction(options: {
102102
options;
103103
const contractURI =
104104
options.params.contractURI ||
105-
(
106-
await upload({
107-
client,
108-
files: [
109-
{
110-
name: params.name,
111-
description: params.description,
112-
symbol: params.symbol,
113-
image: params.image,
114-
external_link: params.external_link,
115-
social_urls: params.social_urls,
116-
seller_fee_basis_points: params.royaltyBps,
117-
fee_recipient: params.royaltyRecipient,
118-
},
119-
],
120-
})
121-
)[0] ||
105+
(await upload({
106+
client,
107+
files: [
108+
{
109+
name: params.name,
110+
description: params.description,
111+
symbol: params.symbol,
112+
image: params.image,
113+
external_link: params.external_link,
114+
social_urls: params.social_urls,
115+
seller_fee_basis_points: params.royaltyBps,
116+
fee_recipient: params.royaltyRecipient,
117+
},
118+
],
119+
})) ||
122120
"";
123121
switch (type) {
124122
case "DropERC721":

0 commit comments

Comments
 (0)