Skip to content

Commit c35a01b

Browse files
fix(zksync): enable contract and account deployment using create2 (#3162)
1 parent cbf3875 commit c35a01b

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

.changeset/fresh-needles-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Provided deployment of accounts and contracts using `create2`

src/zksync/actions/deployContract.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { privateKeyToAccount } from '../../accounts/privateKeyToAccount.js'
55

66
import { deployContract } from './deployContract.js'
77

8-
import { anvilZksync } from '../../../test/src/anvil.js'
8+
import { anvilZksync } from '~test/src/anvil.js'
99
import type { EIP1193RequestFn } from '../../index.js'
1010
import type { DeployContractParameters } from './deployContract.js'
1111

@@ -51,3 +51,14 @@ test('args: factoryDeps', async () => {
5151
`"0x9afe47f3d95eccfc9210851ba5f877f76d372514a26b48bad848a07f77c33b87"`,
5252
)
5353
})
54+
55+
test('create2', async () => {
56+
expect(
57+
await deployContract(client, {
58+
...base,
59+
deploymentType: 'create2',
60+
}),
61+
).toMatchInlineSnapshot(
62+
`"0x9afe47f3d95eccfc9210851ba5f877f76d372514a26b48bad848a07f77c33b87"`,
63+
)
64+
})

src/zksync/actions/deployContract.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import type { Transport } from '../../clients/transports/createTransport.js'
77
import type { ErrorType } from '../../errors/utils.js'
88
import type { ContractConstructorArgs } from '../../types/contract.js'
99
import type { Hash, Hex } from '../../types/misc.js'
10-
import { contractDeployerAddress } from '../constants/address.js'
10+
import {
11+
contract2FactoryAddress,
12+
contractDeployerAddress,
13+
} from '../constants/address.js'
1114
import type { ChainEIP712 } from '../types/chain.js'
1215
import type { ContractDeploymentType } from '../types/contract.js'
1316
import {
@@ -45,7 +48,7 @@ export type DeployContractErrorType =
4548
*
4649
* - Docs: https://viem.sh/docs/contract/deployContract
4750
*
48-
* @param client - Client to use
51+
* @param walletClient - Client to use
4952
* @param parameters - {@link DeployContractParameters}
5053
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
5154
*
@@ -97,7 +100,10 @@ export function deployContract<
97100
return sendEip712Transaction(walletClient, {
98101
...request,
99102
data,
100-
to: contractDeployerAddress,
103+
to:
104+
deploymentType === 'create2' || deploymentType === 'create2Account'
105+
? contract2FactoryAddress
106+
: contractDeployerAddress,
101107
} as unknown as SendEip712TransactionParameters<
102108
chain,
103109
account,

src/zksync/constants/address.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export const contractDeployerAddress =
22
'0x0000000000000000000000000000000000008006' as const
33

4+
export const contract2FactoryAddress =
5+
'0x0000000000000000000000000000000000010000' as const
6+
47
export const legacyEthAddress =
58
'0x0000000000000000000000000000000000000000' as const
69

0 commit comments

Comments
 (0)