thirdweb 5.29.4 → 5.29.5-nightly-a9ce10f39ad47f386e8086e230679093aab08754-20240617192538
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/dist/cjs/exports/extensions/erc721.js +3 -1
- package/dist/cjs/exports/extensions/erc721.js.map +1 -1
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js +116 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js +116 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js +123 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js.map +1 -0
- package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js +89 -0
- package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/exports/extensions/erc721.js +1 -0
- package/dist/esm/exports/extensions/erc721.js.map +1 -1
- package/dist/esm/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js +109 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js +109 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js +116 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js.map +1 -0
- package/dist/esm/extensions/erc721/drops/write/updateMetadata.js +84 -0
- package/dist/esm/extensions/erc721/drops/write/updateMetadata.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/exports/extensions/erc721.d.ts +1 -0
- package/dist/types/exports/extensions/erc721.d.ts.map +1 -1
- package/dist/types/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.d.ts +80 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.d.ts +80 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.d.ts +87 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.d.ts.map +1 -0
- package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts +37 -0
- package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/extensions/erc721.ts +4 -0
- package/src/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.ts +141 -0
- package/src/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.ts +144 -0
- package/src/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.ts +149 -0
- package/src/extensions/erc721/drops/write/updateMetadata.test.ts +127 -0
- package/src/extensions/erc721/drops/write/updateMetadata.ts +123 -0
- package/src/version.ts +1 -1
@@ -0,0 +1,37 @@
|
|
1
|
+
import type { ThirdwebClient } from "../../../../client/client.js";
|
2
|
+
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
|
3
|
+
import type { NFTInput } from "../../../../utils/nft/parseNft.js";
|
4
|
+
import { type UpdateBatchBaseURIParams } from "../../__generated__/DropERC721/write/updateBatchBaseURI.js";
|
5
|
+
export type UpdateMetadataParams = {
|
6
|
+
targetTokenId: bigint;
|
7
|
+
newMetadata: NFTInput;
|
8
|
+
client: ThirdwebClient;
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* @internal
|
12
|
+
*/
|
13
|
+
export declare function getUpdateMetadataParams(options: BaseTransactionOptions<UpdateMetadataParams>): Promise<UpdateBatchBaseURIParams>;
|
14
|
+
/**
|
15
|
+
* Update the metadata of the single token in an NFT Drop (DropERC721) collection
|
16
|
+
* For NFT Collection, please use `setTokenURI`
|
17
|
+
* @param options
|
18
|
+
* @returns the prepared transaction
|
19
|
+
* @extension ERC721
|
20
|
+
* @example
|
21
|
+
* ```ts
|
22
|
+
* import { updateMetadata } from "thirdweb/extensions/erc721";
|
23
|
+
*
|
24
|
+
* const transaction = updateMetadata({
|
25
|
+
* contract,
|
26
|
+
* targetTokenId: 0n,
|
27
|
+
* newMetadata: {
|
28
|
+
* name: "this is the new nft name",
|
29
|
+
* description: "...",
|
30
|
+
* image: "new image uri"
|
31
|
+
* // ...
|
32
|
+
* }
|
33
|
+
* });
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
export declare function updateMetadata(options: BaseTransactionOptions<UpdateMetadataParams>): import("../../../../transaction/prepare-transaction.js").PreparedTransaction<any, import("abitype").AbiFunction, import("../../../../transaction/prepare-transaction.js").PrepareTransactionOptions>;
|
37
|
+
//# sourceMappingURL=updateMetadata.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"updateMetadata.d.ts","sourceRoot":"","sources":["../../../../../../src/extensions/erc721/drops/write/updateMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,EAAO,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EACL,KAAK,wBAAwB,EAE9B,MAAM,4DAA4D,CAAC;AAGpE,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,QAAQ,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,GACpD,OAAO,CAAC,wBAAwB,CAAC,CAsEnC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,wMAOtD"}
|
package/dist/types/version.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const version = "5.29.
|
1
|
+
export declare const version = "5.29.5-nightly-a9ce10f39ad47f386e8086e230679093aab08754-20240617192538";
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,2EAA2E,CAAC"}
|
package/package.json
CHANGED
@@ -163,3 +163,7 @@ export {
|
|
163
163
|
type BatchToReveal,
|
164
164
|
getBatchesToReveal,
|
165
165
|
} from "../../extensions/erc721/lazyMinting/read/getBatchesToReveal.js";
|
166
|
+
export {
|
167
|
+
updateMetadata,
|
168
|
+
type UpdateMetadataParams,
|
169
|
+
} from "../../extensions/erc721/drops/write/updateMetadata.js";
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
2
|
+
import type {
|
3
|
+
BaseTransactionOptions,
|
4
|
+
WithOverrides,
|
5
|
+
} from "../../../../../transaction/types.js";
|
6
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
8
|
+
import { once } from "../../../../../utils/promise/once.js";
|
9
|
+
import type { ThirdwebContract } from "../../../../../contract/contract.js";
|
10
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Represents the parameters for the "freezeBatchBaseURI" function.
|
14
|
+
*/
|
15
|
+
export type FreezeBatchBaseURIParams = WithOverrides<{
|
16
|
+
index: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_index" }>;
|
17
|
+
}>;
|
18
|
+
|
19
|
+
export const FN_SELECTOR = "0xa07ced9e" as const;
|
20
|
+
const FN_INPUTS = [
|
21
|
+
{
|
22
|
+
type: "uint256",
|
23
|
+
name: "_index",
|
24
|
+
},
|
25
|
+
] as const;
|
26
|
+
const FN_OUTPUTS = [] as const;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Checks if the `freezeBatchBaseURI` method is supported by the given contract.
|
30
|
+
* @param contract The ThirdwebContract.
|
31
|
+
* @returns A promise that resolves to a boolean indicating if the `freezeBatchBaseURI` method is supported.
|
32
|
+
* @extension ERC721
|
33
|
+
* @example
|
34
|
+
* ```ts
|
35
|
+
* import { isFreezeBatchBaseURISupported } from "thirdweb/extensions/erc721";
|
36
|
+
*
|
37
|
+
* const supported = await isFreezeBatchBaseURISupported(contract);
|
38
|
+
* ```
|
39
|
+
*/
|
40
|
+
export async function isFreezeBatchBaseURISupported(
|
41
|
+
contract: ThirdwebContract<any>,
|
42
|
+
) {
|
43
|
+
return detectMethod({
|
44
|
+
contract,
|
45
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
46
|
+
});
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Encodes the parameters for the "freezeBatchBaseURI" function.
|
51
|
+
* @param options - The options for the freezeBatchBaseURI function.
|
52
|
+
* @returns The encoded ABI parameters.
|
53
|
+
* @extension ERC721
|
54
|
+
* @example
|
55
|
+
* ```ts
|
56
|
+
* import { encodeFreezeBatchBaseURIParams } "thirdweb/extensions/erc721";
|
57
|
+
* const result = encodeFreezeBatchBaseURIParams({
|
58
|
+
* index: ...,
|
59
|
+
* });
|
60
|
+
* ```
|
61
|
+
*/
|
62
|
+
export function encodeFreezeBatchBaseURIParams(
|
63
|
+
options: FreezeBatchBaseURIParams,
|
64
|
+
) {
|
65
|
+
return encodeAbiParameters(FN_INPUTS, [options.index]);
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Encodes the "freezeBatchBaseURI" function into a Hex string with its parameters.
|
70
|
+
* @param options - The options for the freezeBatchBaseURI function.
|
71
|
+
* @returns The encoded hexadecimal string.
|
72
|
+
* @extension ERC721
|
73
|
+
* @example
|
74
|
+
* ```ts
|
75
|
+
* import { encodeFreezeBatchBaseURI } "thirdweb/extensions/erc721";
|
76
|
+
* const result = encodeFreezeBatchBaseURI({
|
77
|
+
* index: ...,
|
78
|
+
* });
|
79
|
+
* ```
|
80
|
+
*/
|
81
|
+
export function encodeFreezeBatchBaseURI(options: FreezeBatchBaseURIParams) {
|
82
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
83
|
+
// we can do this because we know the specific formats of the values
|
84
|
+
return (FN_SELECTOR +
|
85
|
+
encodeFreezeBatchBaseURIParams(options).slice(
|
86
|
+
2,
|
87
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Prepares a transaction to call the "freezeBatchBaseURI" function on the contract.
|
92
|
+
* @param options - The options for the "freezeBatchBaseURI" function.
|
93
|
+
* @returns A prepared transaction object.
|
94
|
+
* @extension ERC721
|
95
|
+
* @example
|
96
|
+
* ```ts
|
97
|
+
* import { freezeBatchBaseURI } from "thirdweb/extensions/erc721";
|
98
|
+
*
|
99
|
+
* const transaction = freezeBatchBaseURI({
|
100
|
+
* contract,
|
101
|
+
* index: ...,
|
102
|
+
* overrides: {
|
103
|
+
* ...
|
104
|
+
* }
|
105
|
+
* });
|
106
|
+
*
|
107
|
+
* // Send the transaction
|
108
|
+
* ...
|
109
|
+
*
|
110
|
+
* ```
|
111
|
+
*/
|
112
|
+
export function freezeBatchBaseURI(
|
113
|
+
options: BaseTransactionOptions<
|
114
|
+
| FreezeBatchBaseURIParams
|
115
|
+
| {
|
116
|
+
asyncParams: () => Promise<FreezeBatchBaseURIParams>;
|
117
|
+
}
|
118
|
+
>,
|
119
|
+
) {
|
120
|
+
const asyncOptions = once(async () => {
|
121
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
122
|
+
});
|
123
|
+
|
124
|
+
return prepareContractCall({
|
125
|
+
contract: options.contract,
|
126
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
127
|
+
params: async () => {
|
128
|
+
const resolvedOptions = await asyncOptions();
|
129
|
+
return [resolvedOptions.index] as const;
|
130
|
+
},
|
131
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
132
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
133
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
134
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
135
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
136
|
+
maxPriorityFeePerGas: async () =>
|
137
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
138
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
139
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
140
|
+
});
|
141
|
+
}
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
2
|
+
import type {
|
3
|
+
BaseTransactionOptions,
|
4
|
+
WithOverrides,
|
5
|
+
} from "../../../../../transaction/types.js";
|
6
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
8
|
+
import { once } from "../../../../../utils/promise/once.js";
|
9
|
+
import type { ThirdwebContract } from "../../../../../contract/contract.js";
|
10
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Represents the parameters for the "setMaxTotalSupply" function.
|
14
|
+
*/
|
15
|
+
export type SetMaxTotalSupplyParams = WithOverrides<{
|
16
|
+
maxTotalSupply: AbiParameterToPrimitiveType<{
|
17
|
+
type: "uint256";
|
18
|
+
name: "_maxTotalSupply";
|
19
|
+
}>;
|
20
|
+
}>;
|
21
|
+
|
22
|
+
export const FN_SELECTOR = "0x3f3e4c11" as const;
|
23
|
+
const FN_INPUTS = [
|
24
|
+
{
|
25
|
+
type: "uint256",
|
26
|
+
name: "_maxTotalSupply",
|
27
|
+
},
|
28
|
+
] as const;
|
29
|
+
const FN_OUTPUTS = [] as const;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Checks if the `setMaxTotalSupply` method is supported by the given contract.
|
33
|
+
* @param contract The ThirdwebContract.
|
34
|
+
* @returns A promise that resolves to a boolean indicating if the `setMaxTotalSupply` method is supported.
|
35
|
+
* @extension ERC721
|
36
|
+
* @example
|
37
|
+
* ```ts
|
38
|
+
* import { isSetMaxTotalSupplySupported } from "thirdweb/extensions/erc721";
|
39
|
+
*
|
40
|
+
* const supported = await isSetMaxTotalSupplySupported(contract);
|
41
|
+
* ```
|
42
|
+
*/
|
43
|
+
export async function isSetMaxTotalSupplySupported(
|
44
|
+
contract: ThirdwebContract<any>,
|
45
|
+
) {
|
46
|
+
return detectMethod({
|
47
|
+
contract,
|
48
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Encodes the parameters for the "setMaxTotalSupply" function.
|
54
|
+
* @param options - The options for the setMaxTotalSupply function.
|
55
|
+
* @returns The encoded ABI parameters.
|
56
|
+
* @extension ERC721
|
57
|
+
* @example
|
58
|
+
* ```ts
|
59
|
+
* import { encodeSetMaxTotalSupplyParams } "thirdweb/extensions/erc721";
|
60
|
+
* const result = encodeSetMaxTotalSupplyParams({
|
61
|
+
* maxTotalSupply: ...,
|
62
|
+
* });
|
63
|
+
* ```
|
64
|
+
*/
|
65
|
+
export function encodeSetMaxTotalSupplyParams(
|
66
|
+
options: SetMaxTotalSupplyParams,
|
67
|
+
) {
|
68
|
+
return encodeAbiParameters(FN_INPUTS, [options.maxTotalSupply]);
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Encodes the "setMaxTotalSupply" function into a Hex string with its parameters.
|
73
|
+
* @param options - The options for the setMaxTotalSupply function.
|
74
|
+
* @returns The encoded hexadecimal string.
|
75
|
+
* @extension ERC721
|
76
|
+
* @example
|
77
|
+
* ```ts
|
78
|
+
* import { encodeSetMaxTotalSupply } "thirdweb/extensions/erc721";
|
79
|
+
* const result = encodeSetMaxTotalSupply({
|
80
|
+
* maxTotalSupply: ...,
|
81
|
+
* });
|
82
|
+
* ```
|
83
|
+
*/
|
84
|
+
export function encodeSetMaxTotalSupply(options: SetMaxTotalSupplyParams) {
|
85
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
86
|
+
// we can do this because we know the specific formats of the values
|
87
|
+
return (FN_SELECTOR +
|
88
|
+
encodeSetMaxTotalSupplyParams(options).slice(
|
89
|
+
2,
|
90
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Prepares a transaction to call the "setMaxTotalSupply" function on the contract.
|
95
|
+
* @param options - The options for the "setMaxTotalSupply" function.
|
96
|
+
* @returns A prepared transaction object.
|
97
|
+
* @extension ERC721
|
98
|
+
* @example
|
99
|
+
* ```ts
|
100
|
+
* import { setMaxTotalSupply } from "thirdweb/extensions/erc721";
|
101
|
+
*
|
102
|
+
* const transaction = setMaxTotalSupply({
|
103
|
+
* contract,
|
104
|
+
* maxTotalSupply: ...,
|
105
|
+
* overrides: {
|
106
|
+
* ...
|
107
|
+
* }
|
108
|
+
* });
|
109
|
+
*
|
110
|
+
* // Send the transaction
|
111
|
+
* ...
|
112
|
+
*
|
113
|
+
* ```
|
114
|
+
*/
|
115
|
+
export function setMaxTotalSupply(
|
116
|
+
options: BaseTransactionOptions<
|
117
|
+
| SetMaxTotalSupplyParams
|
118
|
+
| {
|
119
|
+
asyncParams: () => Promise<SetMaxTotalSupplyParams>;
|
120
|
+
}
|
121
|
+
>,
|
122
|
+
) {
|
123
|
+
const asyncOptions = once(async () => {
|
124
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
125
|
+
});
|
126
|
+
|
127
|
+
return prepareContractCall({
|
128
|
+
contract: options.contract,
|
129
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
130
|
+
params: async () => {
|
131
|
+
const resolvedOptions = await asyncOptions();
|
132
|
+
return [resolvedOptions.maxTotalSupply] as const;
|
133
|
+
},
|
134
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
135
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
136
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
137
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
138
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
139
|
+
maxPriorityFeePerGas: async () =>
|
140
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
141
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
142
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
143
|
+
});
|
144
|
+
}
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
2
|
+
import type {
|
3
|
+
BaseTransactionOptions,
|
4
|
+
WithOverrides,
|
5
|
+
} from "../../../../../transaction/types.js";
|
6
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
8
|
+
import { once } from "../../../../../utils/promise/once.js";
|
9
|
+
import type { ThirdwebContract } from "../../../../../contract/contract.js";
|
10
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Represents the parameters for the "updateBatchBaseURI" function.
|
14
|
+
*/
|
15
|
+
export type UpdateBatchBaseURIParams = WithOverrides<{
|
16
|
+
index: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_index" }>;
|
17
|
+
uri: AbiParameterToPrimitiveType<{ type: "string"; name: "_uri" }>;
|
18
|
+
}>;
|
19
|
+
|
20
|
+
export const FN_SELECTOR = "0xde903ddd" as const;
|
21
|
+
const FN_INPUTS = [
|
22
|
+
{
|
23
|
+
type: "uint256",
|
24
|
+
name: "_index",
|
25
|
+
},
|
26
|
+
{
|
27
|
+
type: "string",
|
28
|
+
name: "_uri",
|
29
|
+
},
|
30
|
+
] as const;
|
31
|
+
const FN_OUTPUTS = [] as const;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Checks if the `updateBatchBaseURI` method is supported by the given contract.
|
35
|
+
* @param contract The ThirdwebContract.
|
36
|
+
* @returns A promise that resolves to a boolean indicating if the `updateBatchBaseURI` method is supported.
|
37
|
+
* @extension ERC721
|
38
|
+
* @example
|
39
|
+
* ```ts
|
40
|
+
* import { isUpdateBatchBaseURISupported } from "thirdweb/extensions/erc721";
|
41
|
+
*
|
42
|
+
* const supported = await isUpdateBatchBaseURISupported(contract);
|
43
|
+
* ```
|
44
|
+
*/
|
45
|
+
export async function isUpdateBatchBaseURISupported(
|
46
|
+
contract: ThirdwebContract<any>,
|
47
|
+
) {
|
48
|
+
return detectMethod({
|
49
|
+
contract,
|
50
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
51
|
+
});
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Encodes the parameters for the "updateBatchBaseURI" function.
|
56
|
+
* @param options - The options for the updateBatchBaseURI function.
|
57
|
+
* @returns The encoded ABI parameters.
|
58
|
+
* @extension ERC721
|
59
|
+
* @example
|
60
|
+
* ```ts
|
61
|
+
* import { encodeUpdateBatchBaseURIParams } "thirdweb/extensions/erc721";
|
62
|
+
* const result = encodeUpdateBatchBaseURIParams({
|
63
|
+
* index: ...,
|
64
|
+
* uri: ...,
|
65
|
+
* });
|
66
|
+
* ```
|
67
|
+
*/
|
68
|
+
export function encodeUpdateBatchBaseURIParams(
|
69
|
+
options: UpdateBatchBaseURIParams,
|
70
|
+
) {
|
71
|
+
return encodeAbiParameters(FN_INPUTS, [options.index, options.uri]);
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Encodes the "updateBatchBaseURI" function into a Hex string with its parameters.
|
76
|
+
* @param options - The options for the updateBatchBaseURI function.
|
77
|
+
* @returns The encoded hexadecimal string.
|
78
|
+
* @extension ERC721
|
79
|
+
* @example
|
80
|
+
* ```ts
|
81
|
+
* import { encodeUpdateBatchBaseURI } "thirdweb/extensions/erc721";
|
82
|
+
* const result = encodeUpdateBatchBaseURI({
|
83
|
+
* index: ...,
|
84
|
+
* uri: ...,
|
85
|
+
* });
|
86
|
+
* ```
|
87
|
+
*/
|
88
|
+
export function encodeUpdateBatchBaseURI(options: UpdateBatchBaseURIParams) {
|
89
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
90
|
+
// we can do this because we know the specific formats of the values
|
91
|
+
return (FN_SELECTOR +
|
92
|
+
encodeUpdateBatchBaseURIParams(options).slice(
|
93
|
+
2,
|
94
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Prepares a transaction to call the "updateBatchBaseURI" function on the contract.
|
99
|
+
* @param options - The options for the "updateBatchBaseURI" function.
|
100
|
+
* @returns A prepared transaction object.
|
101
|
+
* @extension ERC721
|
102
|
+
* @example
|
103
|
+
* ```ts
|
104
|
+
* import { updateBatchBaseURI } from "thirdweb/extensions/erc721";
|
105
|
+
*
|
106
|
+
* const transaction = updateBatchBaseURI({
|
107
|
+
* contract,
|
108
|
+
* index: ...,
|
109
|
+
* uri: ...,
|
110
|
+
* overrides: {
|
111
|
+
* ...
|
112
|
+
* }
|
113
|
+
* });
|
114
|
+
*
|
115
|
+
* // Send the transaction
|
116
|
+
* ...
|
117
|
+
*
|
118
|
+
* ```
|
119
|
+
*/
|
120
|
+
export function updateBatchBaseURI(
|
121
|
+
options: BaseTransactionOptions<
|
122
|
+
| UpdateBatchBaseURIParams
|
123
|
+
| {
|
124
|
+
asyncParams: () => Promise<UpdateBatchBaseURIParams>;
|
125
|
+
}
|
126
|
+
>,
|
127
|
+
) {
|
128
|
+
const asyncOptions = once(async () => {
|
129
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
130
|
+
});
|
131
|
+
|
132
|
+
return prepareContractCall({
|
133
|
+
contract: options.contract,
|
134
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
135
|
+
params: async () => {
|
136
|
+
const resolvedOptions = await asyncOptions();
|
137
|
+
return [resolvedOptions.index, resolvedOptions.uri] as const;
|
138
|
+
},
|
139
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
140
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
141
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
142
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
143
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
144
|
+
maxPriorityFeePerGas: async () =>
|
145
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
146
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
147
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
148
|
+
});
|
149
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
2
|
+
import { ANVIL_CHAIN } from "~test/chains.js";
|
3
|
+
import { TEST_CLIENT } from "~test/test-clients.js";
|
4
|
+
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
|
5
|
+
|
6
|
+
import {
|
7
|
+
type ThirdwebContract,
|
8
|
+
getContract,
|
9
|
+
} from "../../../../contract/contract.js";
|
10
|
+
import { deployERC721Contract } from "../../../../extensions/prebuilts/deploy-erc721.js";
|
11
|
+
import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js";
|
12
|
+
import type { NFTInput } from "../../../../utils/nft/parseNft.js";
|
13
|
+
import { getNFT } from "../../read/getNFT.js";
|
14
|
+
import { getNFTs } from "../../read/getNFTs.js";
|
15
|
+
import { lazyMint } from "../../write/lazyMint.js";
|
16
|
+
import { getUpdateMetadataParams, updateMetadata } from "./updateMetadata.js";
|
17
|
+
|
18
|
+
let contract: ThirdwebContract;
|
19
|
+
const account = TEST_ACCOUNT_A;
|
20
|
+
const client = TEST_CLIENT;
|
21
|
+
const chain = ANVIL_CHAIN;
|
22
|
+
|
23
|
+
describe("erc721: updateMetadata", () => {
|
24
|
+
beforeEach(async () => {
|
25
|
+
const address = await deployERC721Contract({
|
26
|
+
client,
|
27
|
+
chain,
|
28
|
+
account,
|
29
|
+
type: "DropERC721",
|
30
|
+
params: {
|
31
|
+
name: "NFTDrop",
|
32
|
+
},
|
33
|
+
});
|
34
|
+
contract = getContract({
|
35
|
+
address,
|
36
|
+
client,
|
37
|
+
chain,
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
it("should update the metadata for the selected token | case 1", async () => {
|
42
|
+
const metadatas: NFTInput[] = [
|
43
|
+
{ name: "token 0" },
|
44
|
+
{ name: "token 1" },
|
45
|
+
{ name: "token 2" },
|
46
|
+
];
|
47
|
+
|
48
|
+
const lazyMintTx = lazyMint({ contract, nfts: metadatas });
|
49
|
+
await sendAndConfirmTransaction({ transaction: lazyMintTx, account });
|
50
|
+
|
51
|
+
const transaction = updateMetadata({
|
52
|
+
contract,
|
53
|
+
targetTokenId: 0n,
|
54
|
+
newMetadata: { name: "token 0 - updated" },
|
55
|
+
client,
|
56
|
+
});
|
57
|
+
await sendAndConfirmTransaction({ transaction, account });
|
58
|
+
const nfts = await getNFTs({ contract });
|
59
|
+
expect(nfts[0]?.metadata.name).toBe("token 0 - updated");
|
60
|
+
|
61
|
+
// The other tokens should not change
|
62
|
+
expect(nfts[1]?.metadata.name).toBe("token 1");
|
63
|
+
expect(nfts[2]?.metadata.name).toBe("token 2");
|
64
|
+
});
|
65
|
+
|
66
|
+
it("should update the metadata for the selected token | case 2", async () => {
|
67
|
+
const nftBatch1: NFTInput[] = [
|
68
|
+
{ name: "token 0" },
|
69
|
+
{ name: "token 1" },
|
70
|
+
{ name: "token 2" },
|
71
|
+
];
|
72
|
+
|
73
|
+
const batch1 = lazyMint({ contract, nfts: nftBatch1 });
|
74
|
+
await sendAndConfirmTransaction({ transaction: batch1, account });
|
75
|
+
|
76
|
+
const nftBatch2: NFTInput[] = [
|
77
|
+
{ name: "token 3" },
|
78
|
+
{ name: "token 4" },
|
79
|
+
{ name: "token 5" },
|
80
|
+
];
|
81
|
+
const batch2 = lazyMint({ contract, nfts: nftBatch2 });
|
82
|
+
await sendAndConfirmTransaction({ transaction: batch2, account });
|
83
|
+
|
84
|
+
// firstly, update the token in the first batch
|
85
|
+
const transaction1 = updateMetadata({
|
86
|
+
contract,
|
87
|
+
targetTokenId: 0n,
|
88
|
+
newMetadata: { name: "token 0 - updated" },
|
89
|
+
client,
|
90
|
+
});
|
91
|
+
await sendAndConfirmTransaction({ transaction: transaction1, account });
|
92
|
+
const nft = await getNFT({ contract, tokenId: 0n });
|
93
|
+
expect(nft.metadata.name).toBe("token 0 - updated");
|
94
|
+
|
95
|
+
const tokenUriAfterUpdatedFirstTime = nft.tokenURI;
|
96
|
+
|
97
|
+
// Update token in the second batch
|
98
|
+
const transaction2 = updateMetadata({
|
99
|
+
contract,
|
100
|
+
targetTokenId: 5n,
|
101
|
+
newMetadata: { name: "token 5 - updated" },
|
102
|
+
client,
|
103
|
+
});
|
104
|
+
await sendAndConfirmTransaction({ transaction: transaction2, account });
|
105
|
+
|
106
|
+
const allNfts = await getNFTs({ contract });
|
107
|
+
expect(allNfts[0]?.metadata.name).toBe("token 0 - updated");
|
108
|
+
expect(allNfts.at(-1)?.metadata.name).toBe("token 5 - updated");
|
109
|
+
|
110
|
+
// The tokenUri of tokenId#0 after the second updateMetadata should still be the same
|
111
|
+
// since it belong to another batch
|
112
|
+
expect(allNfts[0]?.tokenURI).toBe(tokenUriAfterUpdatedFirstTime);
|
113
|
+
});
|
114
|
+
|
115
|
+
it("should throw error if there's no batch", async () => {
|
116
|
+
await expect(() =>
|
117
|
+
getUpdateMetadataParams({
|
118
|
+
contract,
|
119
|
+
targetTokenId: 0n,
|
120
|
+
newMetadata: { name: "token 0 - updated" },
|
121
|
+
client,
|
122
|
+
}),
|
123
|
+
).rejects.toThrowError(
|
124
|
+
"No base URI set. Please set a base URI before updating metadata",
|
125
|
+
);
|
126
|
+
});
|
127
|
+
});
|