Accounts


Accounts

PrivateKeyEthSigner

Used to get wallet address, generate signatures, and verify messages.

Create from credentials and chain id

Example

Inputs and outputs

NameDescription
credentialsCredentials object.
chainIdChain id of the network.
returnsPrivateKeyEthSigner.

signTypedData

String signature = signer.signTypedData(domain, message).join();

Signs typed-struct using Ethereum private key with the EIP-712 signature standard.

Inputs and outputs

NameDescription
domainEIP712 domain.
typedDataObject implementing EIP712 structure standard.
returnsPrepared gas estimate request.

verifyTypedData

Verify typed, EIP-712 struct standard.

boolean verified = signer.verifyTypedData(domain, message, signature).join();

Inputs and outputs

NameDescription
domainEIP712 domain.
typedDataObject implementing EIP712 structure standard.
returnsPrepared gas estimate request.

signMessage

Sign raw message.

signer.signMessage(Eip712Encoder.typedDataToSignedBytes(domain, typedData), false);

Inputs and outputs

NameDescription
messageMessage to sign.
addPrefixIf true then add secure prefix (EIP-712).
returnsSignature object.

verifySignature

Verify signature with raw message.

signer.verifySignature(signature, Eip712Encoder.typedDataToSignedBytes(domain, typedData), false);

Inputs and outputs

NameDescription
signatureSignature string.
messageMessage to verify in bytes.
prefixedIf true then add secure prefix (EIP-712).
returnstrue on verification success.

getAddress

Get wallet address.

signer.getAddress();

Inputs and outputs

NameDescription
returnsAddress in hex string.

Wallet

Creating wallet from a private key

The Wallet object from zksync-web3 can be created from an Ethereum private key. Example

Inputs and outputs

NameDescription
zksyncA zkSync Era node provider. Needed for interaction with zkSync Era.
signerUsed to get wallet address, generate signatures, and verify messages.
tokenToken object.
returnsThe new Wallet object.

transfer

There are multiple ways to transfer coins or tokens with a wallet object.

Transfer coins

Native coins example

NameDescription
toRecipient address.
amountAmount of funds to be transferred in minimum denomination (wei).
returnsPrepared remote call of transaction.
Transfer coins or tokens
With specific token

Example

NameDescription
toRecipient address.
amountAmount of funds to be transferred in minimum denomination (wei).
tokenToken object supported by ZkSync Era.
returnsPrepared remote call of transaction.
With specific token and custom nonce
NameDescription
toRecipient address.
amountAmount of funds to be transferred in minimum denomination (wei).
tokenToken object supported by ZkSync Era.
nonceCustom nonce value of the wallet.
returnsPrepared remote call of transaction.

withdraw

Withdraw native coins or tokens from L1.

Example

NameDescription
toAddress of the L1 wallet from which funds will be withdrawn.
amountAmount of funds to be withdrawn.
returnsPrepared remote call of transaction.

With specific token

NameDescription
toAddress of the L1 wallet L1 from which funds will be withdrawn.
amountAmount of funds to be withdrawn.
tokenToken object supported by ZkSync Era.
returnsPrepared remote call of transaction.

With specific token and custom nonce

NameDescription
toAddress of the L1 wallet from which funds will be withdrawn.
amountAmount of funds to be withdrawn.
tokenToken object supported by ZkSync Era.
nonceCustom nonce value of the wallet.
returnsPrepared remote call of transaction.

deploy

Deploy new smart contract onto chain (this method uses create2, see EIP-1014)

Example

NameDescription
bytecodeCompiled bytecode of the contract.
returnsPrepared remote call of transaction.

With constructor

Example

NameDescription
bytecodeCompiled bytecode of the contract.
calldataEncoded constructor parameter(s) of contract.
returnsPrepared remote call of transaction.

With constructor and custom nonce

NameDescription
bytecodeCompiled bytecode of the contract.
calldataEncoded constructor parameter(s) of contract.
nonceCustom nonce value of the wallet.
returnsPrepared remote call of transaction.

execute

Execute function of deployed contract.

Example

NameDescription
contractAddressAddress of deployed contract.
functionPrepared function call with or without parameters.
returnsPrepared remote call of transaction.

With custom nonce

NameDescription
contractAddressAddress of deployed contract.
functionPrepared function call with or without parameters.
nonceCustom nonce value of the wallet.
returnsPrepared remote call of transaction.

getBalance

Get balance of wallet in native coin

BigInteger balance = wallet.getBalance().send();
NameDescription
addressWallet address.
returnsPrepared get balance call.

Get balance of wallet in token

Token token = new Token("L1_ADDRESS", "L2_ADDRESS", "SYMBOL", 18);
BigInteger = wallet.getBalance(token).send();
NameDescription
tokenToken object supported by ZkSync Era.
returnsPrepared get balance call.

Get balance of wallet by address of token

Token token = new Token("L1_ADDRESS", "L2_ADDRESS", "SYMBOL", 18);
BigInteger = wallet.getBalance("ADDRESS" ,token).send();
NameDescription
addressWallet address.
tokenToken object supported by ZkSync Era.
returnsPrepared get balance call.

Get balance of wallet by address of token at block DefaultBlockParameter

BigInteger = wallet.getBalance(address, token, ZkBlockParameterName.COMMITTED).send();
NameDescription
addressWallet address.
tokenToken object supported by ZkSync Era.
atBlock variant.
returnsPrepared get balance call.

getNonce

Get nonce for wallet at block DefaultBlockParameter

BigInteger = wallet.getNonce(ZkBlockParameterName.COMMITTED).send(); //ZkBlockParameterName.FINALIZED
NameDescription
atBlock variant.
returnsPrepared get nonce call.

Get nonce for wallet at block COMMITTED ZkBlockParameterName

BigInteger = wallet.getNonce().send();
NameDescription
returnsPrepared get nonce call.