Contract Interfaces
zksync2-java
implements contract wrappers. Created using
web3j CLI
Generated wrappers
ERC20
IEthToken
IL1Bridge
IL1Messenger
IL2Bridge
INonceHolder
IZkSync
ZkSyncContract
ContractFactory
The ContractDeployer
class is a utility class for deploying smart contracts on ZKsync,
using create
and create2
methods.
It provides methods to compute contract addresses,
based on EIP-1014
(create2) and extract contract addresses from transaction receipts.
computeL2Create2Address
Compute contract address according EIP-1014
Inputs
Parameter | Type | Description |
---|---|---|
sender | Address | The address of the transaction sender. |
bytecode | byte | The compiled contract bytecode. |
constructor | byte | The encoded constructor parameters. |
salt | byte | A 32-byte value used for the address computation. |
Example
String result = ContractDeployer.computeL2Create2Address(new Address(credentials.getAddress()), Numeric.hexStringToByteArray(CounterContract.BINARY), new byte[]{}, salt).getValue();
computeL2CreateAddress
Computes the contract address using the create method.
Inputs
Parameter | Type | Description |
---|---|---|
sender | Address | Address of a source of a transaction. |
nonce | BigInteger | Deployment nonce. |
Example
INonceHolder nonceHolder = INonceHolder.load(ZkSyncAddresses.NONCE_HOLDER_ADDRESS, zksync, new ReadonlyTransactionManager(zksync, credentials.getAddress()), new DefaultGasProvider());
BigInteger deploymentNonce = nonceHolder.getDeploymentNonce(credentials.getAddress()).send();
String precomputedAddress = ContractDeployer.computeL2CreateAddress(new Address(credentials.getAddress()), deploymentNonce).getValue();
encodeCreate
Encode create
deployment function of default factory contract
Inputs
Parameter | Type | Description |
---|---|---|
bytecode | byte | The compiled contract bytecode. |
calldata | byte | Encoded constructor parameters. |
Example
ContractDeployer.encodeCreate(bytecodeBytes, calldataBytes)
encodeCreate2
Encodes the create2 deployment function with empty constructor parameters.
Inputs
Parameter | Type | Description |
---|---|---|
bytecode | byte | The compiled contract bytecode. |
calldata | byte | Encoded constructor parameters. |
salt | byte | 32 bytes salt. |
Example
byte[] salt = SecureRandom.getSeed(32);
ContractDeployer.encodeCreate2(bytecodeBytes, calldataBytes, salt)
encodeCreate2Account
Encodes the create2 deployment function for a custom account with empty constructor parameters EIP-4337.
Inputs
Parameter | Type | Description |
---|---|---|
bytecode | byte | The compiled contract bytecode. |
calldata | byte | Encoded constructor parameters. |
salt | byte | 32 bytes salt. |
accountAbstractionVersion | AccountAbstractionVersion | Version of the account abstraction. |
Example
ContractDeployer.encodeCreate2Account(bytecodeBytes, calldataBytes, salt, AccountAbstractionVersion.Version1)
encodeCreateAccount
Encode create
deployment custom account function of default factory contract EIP-4337
Inputs
Parameter | Type | Description |
---|---|---|
bytecode | byte | The compiled contract bytecode. |
calldata | byte | Encoded constructor parameters. |
Example
ContractDeployer.encodeCreate2Account(bytecodeBytes, calldataBytes, AccountAbstractionVersion.Version1)
extractContractAddress
Extracts the deployed contract address from a transaction receipt.
Inputs
Parameter | Type | Description |
---|---|---|
receipt | TransactionReceipt | The transaction receipt. |
Example
String correctContractAddress = ContractDeployer.extractContractAddress(response).getValue();
hashBytecode
Generates the SHA-256 hash of the contract bytecode.
Inputs
Parameter | Type | Description |
---|---|---|
bytecode | byte | The compiled contract bytecode. |
Example
byte[] result = ContractDeployer.hashBytecode(Numeric.hexStringToByteArray(CounterContract.BINARY));