File tree 7 files changed +94
-2
lines changed
contract/deployment/utils 7 files changed +94
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " thirdweb " : minor
3
+ ---
4
+
5
+ Added new deployment utility functions to help manage infrastructure contracts and initialization:
6
+
7
+ - ` getInitializeTransaction ` : Prepare initialization transaction for contract deployment
8
+ - ` getOrDeployInfraForPublishedContract ` : Get or deploy required infrastructure for published contracts
9
+
10
+ ``` typescript
11
+ import {
12
+ getInitializeTransaction ,
13
+ getOrDeployInfraForPublishedContract
14
+ } from " thirdweb" ;
15
+
16
+ // Get initialization transaction
17
+ const initTx = await getInitializeTransaction ({
18
+ client ,
19
+ chain ,
20
+ account ,
21
+ implementationContract ,
22
+ deployMetadata ,
23
+ initializeParams: {
24
+ name: " My Contract" ,
25
+ symbol: " CNTRCT"
26
+ }
27
+ });
28
+
29
+ // Get or deploy infrastructure
30
+ const infra = await getOrDeployInfraForPublishedContract ({
31
+ chain ,
32
+ client ,
33
+ account ,
34
+ contractId: " MyContract" ,
35
+ constructorParams: params
36
+ });
37
+ ```
Original file line number Diff line number Diff line change @@ -22,7 +22,19 @@ import {
22
22
} from "./infra.js" ;
23
23
24
24
/**
25
- * @internal
25
+ * Gets or deploys the infrastructure contracts needed for a published contract deployment
26
+ * @param args - The arguments object
27
+ * @param args.chain - The blockchain network configuration
28
+ * @param args.client - The ThirdwebClient instance
29
+ * @param args.account - The account performing the deployment
30
+ * @param args.contractId - The ID of the contract to deploy
31
+ * @param args.constructorParams - Optional constructor parameters for the implementation contract
32
+ * @param args.publisher - Optional publisher address, defaults to thirdweb
33
+ * @param args.version - Optional version of the contract to deploy
34
+ * @returns An object containing:
35
+ * - cloneFactoryContract: The factory contract used for creating clones
36
+ * - implementationContract: The deployed implementation contract
37
+ * @contract
26
38
*/
27
39
export async function getOrDeployInfraForPublishedContract (
28
40
args : ClientAndChainAndAccount & {
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ import type { ClientAndChain } from "../../../utils/types.js";
2
2
import { getDeployedInfraContract } from "./infra.js" ;
3
3
4
4
/**
5
+ * Retrieves the deployed clone factory contract instance if available
6
+ * @param args - Client and chain information required to locate the contract
7
+ * @returns Promise that resolves to the clone factory contract instance if deployed, null otherwise
8
+ *
5
9
* @internal
6
10
*/
7
11
export async function getDeployedCloneFactoryContract ( args : ClientAndChain ) {
Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ type GetDeployedInfraParams = Prettify<
28
28
> ;
29
29
30
30
/**
31
+ * Retrieves a deployed infrastructure contract instance for the specified contract ID
32
+ * @param options - Configuration options for locating the infrastructure contract
33
+ * @param options.client - ThirdwebClient instance
34
+ * @param options.chain - Target blockchain network
35
+ * @param options.contractId - Identifier for the infrastructure contract (e.g. "WETH9", "Forwarder")
36
+ * @param options.constructorParams - Optional constructor parameters for contract initialization
37
+ * @param options.publisher - Optional custom publisher address
38
+ * @param options.version - Optional specific contract version to retrieve
39
+ * @returns Promise that resolves to the contract instance if deployed, null otherwise
40
+ *
31
41
* @internal
32
42
*/
33
43
export async function getDeployedInfraContract (
Original file line number Diff line number Diff line change @@ -54,3 +54,6 @@ export {
54
54
type DeployPackContractOptions ,
55
55
deployPackContract ,
56
56
} from "../extensions/prebuilts/deploy-pack.js" ;
57
+
58
+ export { getInitializeTransaction } from "../extensions/prebuilts/deploy-published.js" ;
59
+ export { getOrDeployInfraForPublishedContract } from "../contract/deployment/utils/bootstrap.js" ;
Original file line number Diff line number Diff line change @@ -278,7 +278,22 @@ async function directDeploy(options: {
278
278
} ) ;
279
279
}
280
280
281
- async function getInitializeTransaction ( options : {
281
+ /**
282
+ * Prepares the initialization transaction for a contract deployment
283
+ * @param options - The options for generating the initialize transaction
284
+ * @param options.client - The ThirdwebClient instance
285
+ * @param options.chain - The blockchain network configuration
286
+ * @param options.account - The account performing the initialization
287
+ * @param options.implementationContract - The contract implementation to initialize
288
+ * @param options.deployMetadata - The metadata for the contract deployment
289
+ * @param options.initializeParams - Optional parameters to pass to the initialize function
290
+ * @param options.modules - Optional array of modules to install during initialization
291
+ * @param options.modules[].deployMetadata - The metadata for the module contract
292
+ * @param options.modules[].initializeParams - Optional parameters for module initialization
293
+ * @returns The prepared transaction for contract initialization
294
+ * @contract
295
+ */
296
+ export async function getInitializeTransaction ( options : {
282
297
client : ThirdwebClient ;
283
298
chain : Chain ;
284
299
account : Account ;
Original file line number Diff line number Diff line change @@ -209,6 +209,17 @@ async function getTransactionsForMaketplaceV3(options: {
209
209
return transactions ;
210
210
}
211
211
212
+ /**
213
+ * Gets the default constructor parameters required for contract implementation deployment
214
+ * @param args - The arguments object
215
+ * @param args.chain - The blockchain network configuration
216
+ * @param args.client - The ThirdwebClient instance
217
+ * @returns An object containing default constructor parameters:
218
+ * - On zkSync chains: returns an empty object since no parameters are needed
219
+ * - On other chains: returns `trustedForwarder` and `nativeTokenWrapper` addresses
220
+ *
221
+ * @internal
222
+ */
212
223
export async function getAllDefaultConstructorParamsForImplementation ( args : {
213
224
chain : Chain ;
214
225
client : ThirdwebClient ;
You can’t perform that action at this time.
0 commit comments