File tree Expand file tree Collapse file tree 7 files changed +94
-2
lines changed
contract/deployment/utils Expand file tree Collapse file tree 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 {
2222} from "./infra.js" ;
2323
2424/**
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
2638 */
2739export async function getOrDeployInfraForPublishedContract (
2840 args : ClientAndChainAndAccount & {
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ import type { ClientAndChain } from "../../../utils/types.js";
22import { getDeployedInfraContract } from "./infra.js" ;
33
44/**
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+ *
59 * @internal
610 */
711export async function getDeployedCloneFactoryContract ( args : ClientAndChain ) {
Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ type GetDeployedInfraParams = Prettify<
2828> ;
2929
3030/**
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+ *
3141 * @internal
3242 */
3343export async function getDeployedInfraContract (
Original file line number Diff line number Diff line change @@ -54,3 +54,6 @@ export {
5454 type DeployPackContractOptions ,
5555 deployPackContract ,
5656} 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: {
278278 } ) ;
279279}
280280
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 : {
282297 client : ThirdwebClient ;
283298 chain : Chain ;
284299 account : Account ;
Original file line number Diff line number Diff line change @@ -209,6 +209,17 @@ async function getTransactionsForMaketplaceV3(options: {
209209 return transactions ;
210210}
211211
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+ */
212223export async function getAllDefaultConstructorParamsForImplementation ( args : {
213224 chain : Chain ;
214225 client : ThirdwebClient ;
You can’t perform that action at this time.
0 commit comments