JSON-RPC API
As per the EIP-1193 specification, the zkEVM provider exposes a request
function,
which is intended to act as a transport and protocol agnostic wrapper for Remote Procedure Calls (RPCs):
export interface RequestArguments {
method: string;
params?: Array<any>;
}
export type Provider = {
request: (request: RequestArguments) => Promise<any>;
// ...
}
Error Handling
The request
method may reject with a JsonRpcError
error:
export class JsonRpcError extends Error {
public readonly message: string;
public readonly code: ProviderErrorCode | RpcErrorCode;
}
export enum ProviderErrorCode {
USER_REJECTED_REQUEST = 4001,
UNAUTHORIZED = 4100,
UNSUPPORTED_METHOD = 4200,
DISCONNECTED = 4900,
}
export enum RpcErrorCode {
RPC_SERVER_ERROR = -32000,
INVALID_REQUEST = -32600,
METHOD_NOT_FOUND = -32601,
INVALID_PARAMS = -32602,
INTERNAL_ERROR = -32603,
PARSE_ERROR = -32700,
USER_REJECTED_REQUEST = -32003,
}
Supported RPC Methods
The zkEVM provider supports the following RPC methods:
📄️ eth_requestAccounts
This method attempts to authenticate the user and initialises their Passport wallet before returning an array of wallet addresses.
📄️ eth_sendTransaction
Creates new message call transaction or a contract creation, if the data field contains code.
📄️ eth_accounts
Returns the list of Passport accounts that the user has authorised to connect to the dApp.
📄️ eth_gasPrice
Returns the current gas price in wei.
📄️ eth_getBalance
Returns the balance of the account of given address in wei.
📄️ eth_getStorageAt
Returns the value from a storage position at a given address.
📄️ eth_estimateGas
Returns an estimate of the gas that would be used in a transaction with the given parameters.
📄️ eth_call
Executes a new message call immediately without creating a transaction on the blockchain.
📄️ eth_blockNumber
Returns the number of most recent block.
📄️ eth_chainId
Returns the current chain id.
📄️ eth_getBlockByHash
Returns information about a block by hash.
📄️ eth_getBlockByNumber
Returns information about a block by number.
📄️ eth_getTransactionByHash
Returns the information about a transaction requested by transaction hash.
📄️ eth_getTransactionReceipt
Returns the receipt of a transaction requested by transaction hash.
📄️ eth_getTransactionCount
Returns the number of transactions sent from an address.
📄️ eth_getCode
Returns the bytecode of a smart contract at a given address.
📄️ eth_signTypedData_v4
Enables passport users to sign EIP-712 structured messages off-chain.
📄️ personal_sign
Enables passport users to sign ERC-191 personal messages off-chain.