Skip to content

Commit f5abbe8

Browse files
feat: Add deployPublishedContract deploy extension (#2788)
1 parent b1d9e4a commit f5abbe8

File tree

7 files changed

+528
-272
lines changed

7 files changed

+528
-272
lines changed

.changeset/poor-trainers-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Added `deployPublishedContract`

packages/thirdweb/src/contract/deployment/deploy-with-abi.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import type {
33
AbiParameter,
44
AbiParametersToPrimitiveTypes,
55
} from "abitype";
6+
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
67
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
78
import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js";
89
import { ensureBytecodePrefix } from "../../utils/bytecode/prefix.js";
910
import { concatHex } from "../../utils/encoding/helpers/concat-hex.js";
1011
import { type Hex, isHex } from "../../utils/encoding/hex.js";
1112
import type { Prettify } from "../../utils/type-utils.js";
1213
import type { ClientAndChain } from "../../utils/types.js";
14+
import type { Account } from "../../wallets/interfaces/wallet.js";
1315

1416
export type PrepareDirectDeployTransactionOptions<
1517
TConstructor extends AbiConstructor,
@@ -67,3 +69,42 @@ export function prepareDirectDeployTransaction<
6769
]),
6870
});
6971
}
72+
73+
/**
74+
* Deploy a contract on a given chain
75+
* @param options - the deploy options
76+
* @returns - a promise that resolves to the deployed contract address
77+
* @example
78+
* ```ts
79+
* import { deployContract } from "thirdweb/deployContract";
80+
*
81+
* const address = await deployContract({
82+
* client,
83+
* chain,
84+
* bytecode: "0x...",
85+
* constructorAbi: {
86+
* inputs: [{ type: "uint256", name: "value" }],
87+
* type: "constructor",
88+
* },
89+
* constructorParams: [123],
90+
* });
91+
* ```
92+
* @extension DEPLOY
93+
*/
94+
export async function deployContract<const TConstructor extends AbiConstructor>(
95+
options: PrepareDirectDeployTransactionOptions<TConstructor> & {
96+
account: Account;
97+
},
98+
) {
99+
const deployTx = prepareDirectDeployTransaction(options);
100+
const receipt = await sendAndConfirmTransaction({
101+
account: options.account,
102+
transaction: deployTx,
103+
});
104+
if (!receipt.contractAddress) {
105+
throw new Error(
106+
`Could not find deployed contract address in transaction: ${receipt.transactionHash}`,
107+
);
108+
}
109+
return receipt.contractAddress;
110+
}

packages/thirdweb/src/exports/deploys.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,15 @@ export {
1919
deployERC1155Contract,
2020
} from "../extensions/prebuilts/deploy-erc1155.js";
2121

22+
export {
23+
deployPublishedContract,
24+
type DeployPublishedContractOptions,
25+
} from "../extensions/prebuilts/deploy-published.js";
26+
2227
export { prepareDirectDeployTransaction } from "../contract/deployment/deploy-with-abi.js";
28+
export { prepareAutoFactoryDeployTransaction } from "../contract/deployment/deploy-via-autofactory.js";
2329
export { deployViaAutoFactory } from "../contract/deployment/deploy-via-autofactory.js";
30+
export {
31+
deployContract,
32+
type PrepareDirectDeployTransactionOptions,
33+
} from "../contract/deployment/deploy-with-abi.js";

packages/thirdweb/src/extensions/erc721/write/sigMint.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { generateMintSignature, mintWithSignature } from "./sigMint.js";
2121
describe.runIf(process.env.TW_SECRET_KEY)(
2222
"generateMintSignature",
2323
{
24-
timeout: 60000,
24+
timeout: 120000,
2525
},
2626
() => {
2727
let erc721Contract: ThirdwebContract;
@@ -42,7 +42,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
4242
chain: ANVIL_CHAIN,
4343
client: TEST_CLIENT,
4444
});
45-
});
45+
}, 60000);
4646

4747
it("should generate a mint signature and mint an NFT", async () => {
4848
const { payload, signature } = await generateMintSignature({

0 commit comments

Comments
 (0)