Skip to content

Commit ac42c45

Browse files
committed
[SDK] Feature: Export contract deployment utilities (#5501)
CNCT-2441 <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces new utility functions and enhances existing ones to improve the management of infrastructure contracts and initialization processes within the `thirdweb` framework. ### Detailed summary - Added `getInitializeTransaction` for preparing contract initialization transactions. - Added `getOrDeployInfraForPublishedContract` to manage infrastructure for published contracts. - Documented various functions with detailed JSDoc comments. - Enhanced `getDeployedCloneFactoryContract` and `getDeployedInfraContract` with clearer descriptions. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent adda60c commit ac42c45

File tree

7 files changed

+94
-2
lines changed

7 files changed

+94
-2
lines changed

.changeset/long-queens-draw.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
```

packages/thirdweb/src/contract/deployment/utils/bootstrap.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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
*/
2739
export async function getOrDeployInfraForPublishedContract(
2840
args: ClientAndChainAndAccount & {

packages/thirdweb/src/contract/deployment/utils/clone-factory.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { ClientAndChain } from "../../../utils/types.js";
22
import { 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
*/
711
export async function getDeployedCloneFactoryContract(args: ClientAndChain) {

packages/thirdweb/src/contract/deployment/utils/infra.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/
3343
export async function getDeployedInfraContract(

packages/thirdweb/src/exports/deploys.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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";

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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;

packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
*/
212223
export async function getAllDefaultConstructorParamsForImplementation(args: {
213224
chain: Chain;
214225
client: ThirdwebClient;

0 commit comments

Comments
 (0)