-
Notifications
You must be signed in to change notification settings - Fork 597
Expand file tree
/
Copy pathutil.ts
More file actions
43 lines (38 loc) · 1.38 KB
/
util.ts
File metadata and controls
43 lines (38 loc) · 1.38 KB
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
import { EthAddress } from '@aztec/aztec.js';
import type { ExtendedViemWalletClient } from '@aztec/ethereum';
import { jsonStringify } from '@aztec/foundation/json-rpc';
import type { Hex } from '@spalladino/viem';
import type { Abi, Narrow } from 'abitype';
/**
* Helper function to deploy ETH contracts.
* @param l1Client - A viem WalletClient extended with public actions.
* @param abi - The ETH contract's ABI (as abitype's Abi).
* @param bytecode - The ETH contract's bytecode.
* @param args - Constructor arguments for the contract.
* @returns The ETH address the contract was deployed to.
*/
export async function deployL1Contract(
l1Client: ExtendedViemWalletClient,
abi: Narrow<Abi | readonly unknown[]>,
bytecode: Hex,
args: readonly unknown[] = [],
): Promise<EthAddress> {
const hash = await l1Client.deployContract({
abi,
bytecode,
args,
});
const receipt = await l1Client.waitForTransactionReceipt({ hash });
const contractAddress = receipt.contractAddress;
if (!contractAddress) {
throw new Error(`No contract address found in receipt: ${jsonStringify(receipt)}`);
}
return EthAddress.fromString(receipt.contractAddress!);
}
/**
* Sleep for a given number of milliseconds.
* @param ms - the number of milliseconds to sleep for
*/
export function delay(ms: number): Promise<void> {
return new Promise<void>(resolve => setTimeout(resolve, ms));
}