Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .changeset/long-queens-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
"thirdweb": minor
---

Added new deployment utility functions to help manage infrastructure contracts and initialization:

- `getInitializeTransaction`: Prepare initialization transaction for contract deployment
- `getOrDeployInfraForPublishedContract`: Get or deploy required infrastructure for published contracts

```typescript
import {
getInitializeTransaction,
getOrDeployInfraForPublishedContract
} from "thirdweb";

// Get initialization transaction
const initTx = await getInitializeTransaction({
client,
chain,
account,
implementationContract,
deployMetadata,
initializeParams: {
name: "My Contract",
symbol: "CNTRCT"
}
});

// Get or deploy infrastructure
const infra = await getOrDeployInfraForPublishedContract({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we just expose this one for now? instead of getDeployedInfraContract and getDeployedCloneFactory ?

chain,
client,
account,
contractId: "MyContract",
constructorParams: params
});
```
14 changes: 13 additions & 1 deletion packages/thirdweb/src/contract/deployment/utils/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ import {
} from "./infra.js";

/**
* @internal
* Gets or deploys the infrastructure contracts needed for a published contract deployment
* @param args - The arguments object
* @param args.chain - The blockchain network configuration
* @param args.client - The ThirdwebClient instance
* @param args.account - The account performing the deployment
* @param args.contractId - The ID of the contract to deploy
* @param args.constructorParams - Optional constructor parameters for the implementation contract
* @param args.publisher - Optional publisher address, defaults to thirdweb
* @param args.version - Optional version of the contract to deploy
* @returns An object containing:
* - cloneFactoryContract: The factory contract used for creating clones
* - implementationContract: The deployed implementation contract
* @contract
*/
export async function getOrDeployInfraForPublishedContract(
args: ClientAndChainAndAccount & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { ClientAndChain } from "../../../utils/types.js";
import { getDeployedInfraContract } from "./infra.js";

/**
* Retrieves the deployed clone factory contract instance if available
* @param args - Client and chain information required to locate the contract
* @returns Promise that resolves to the clone factory contract instance if deployed, null otherwise
*
* @internal
*/
export async function getDeployedCloneFactoryContract(args: ClientAndChain) {
Expand Down
10 changes: 10 additions & 0 deletions packages/thirdweb/src/contract/deployment/utils/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ type GetDeployedInfraParams = Prettify<
>;

/**
* Retrieves a deployed infrastructure contract instance for the specified contract ID
* @param options - Configuration options for locating the infrastructure contract
* @param options.client - ThirdwebClient instance
* @param options.chain - Target blockchain network
* @param options.contractId - Identifier for the infrastructure contract (e.g. "WETH9", "Forwarder")
* @param options.constructorParams - Optional constructor parameters for contract initialization
* @param options.publisher - Optional custom publisher address
* @param options.version - Optional specific contract version to retrieve
* @returns Promise that resolves to the contract instance if deployed, null otherwise
*
* @internal
*/
export async function getDeployedInfraContract(
Expand Down
3 changes: 3 additions & 0 deletions packages/thirdweb/src/exports/deploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ export {
type DeployPackContractOptions,
deployPackContract,
} from "../extensions/prebuilts/deploy-pack.js";

export { getInitializeTransaction } from "../extensions/prebuilts/deploy-published.js";
export { getOrDeployInfraForPublishedContract } from "../contract/deployment/utils/bootstrap.js";
17 changes: 16 additions & 1 deletion packages/thirdweb/src/extensions/prebuilts/deploy-published.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,22 @@ async function directDeploy(options: {
});
}

async function getInitializeTransaction(options: {
/**
* Prepares the initialization transaction for a contract deployment
* @param options - The options for generating the initialize transaction
* @param options.client - The ThirdwebClient instance
* @param options.chain - The blockchain network configuration
* @param options.account - The account performing the initialization
* @param options.implementationContract - The contract implementation to initialize
* @param options.deployMetadata - The metadata for the contract deployment
* @param options.initializeParams - Optional parameters to pass to the initialize function
* @param options.modules - Optional array of modules to install during initialization
* @param options.modules[].deployMetadata - The metadata for the module contract
* @param options.modules[].initializeParams - Optional parameters for module initialization
* @returns The prepared transaction for contract initialization
* @contract
*/
export async function getInitializeTransaction(options: {
client: ThirdwebClient;
chain: Chain;
account: Account;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ async function getTransactionsForMaketplaceV3(options: {
return transactions;
}

/**
* Gets the default constructor parameters required for contract implementation deployment
* @param args - The arguments object
* @param args.chain - The blockchain network configuration
* @param args.client - The ThirdwebClient instance
* @returns An object containing default constructor parameters:
* - On zkSync chains: returns an empty object since no parameters are needed
* - On other chains: returns `trustedForwarder` and `nativeTokenWrapper` addresses
*
* @internal
*/
export async function getAllDefaultConstructorParamsForImplementation(args: {
chain: Chain;
client: ThirdwebClient;
Expand Down
Loading