-
Notifications
You must be signed in to change notification settings - Fork 242
/
compute-published-contract-address.ts
61 lines (59 loc) · 1.96 KB
/
compute-published-contract-address.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import type { Chain } from "../../chains/types.js";
import type { ThirdwebClient } from "../../client/client.js";
import { computeDeploymentAddress } from "./compute-deployment-address.js";
import {
computeDeploymentInfoFromContractId,
computeDeploymentInfoFromMetadata,
} from "./compute-published-contract-deploy-info.js";
import type { FetchDeployMetadataResult } from "./deploy-metadata.js";
/**
* Predicts the implementation address of any published contract
* @param args - The arguments for predicting the address of a published contract.
* @param args.client - The Thirdweb client.
* @param args.chain - The chain to predict the address on.
* @param args.constructorParams - The parameters for the contract constructor.
* @param args.contractId - The contract id.
* @param args.publisher - The publisher of the contract.
* @param args.version - The version of the contract.
* @example
* ```ts
* import { computePublishedContractAddress } from "thirdweb/deploys";
*
* const contractMetadata = await fetchPublishedContractMetadata({
* client,
* chain,
* });
* const address = await computePublishedContractAddress({
* client,
* chain,
* contractId: "AccountFactory",
* constructorParams,
* });
* ```
* @returns A promise that resolves to the predicted address of the contract.
*/
export async function computePublishedContractAddress(args: {
client: ThirdwebClient;
chain: Chain;
contractId: string;
constructorParams: unknown[];
publisher?: string;
version?: string;
salt?: string;
}): Promise<string> {
const info = await computeDeploymentInfoFromContractId(args);
return computeDeploymentAddress(info);
}
/**
* @internal
*/
export async function computeContractAddress(args: {
client: ThirdwebClient;
chain: Chain;
contractMetadata: FetchDeployMetadataResult;
constructorParams: unknown[];
salt?: string;
}): Promise<string> {
const info = await computeDeploymentInfoFromMetadata(args);
return computeDeploymentAddress(info);
}