Overview
All SDK operations either:- Throw a
ZKsyncErrorwhose.envelopegives you a structured, stable payload, or - Return a result object from the
try*variants:{ ok: true, value } | { ok: false, error }.
What gets thrown
When the SDK throws, it throws an instance ofZKsyncError. Use isZKsyncError(e) to narrow and read the error envelope.
Envelope shape
'ZKsyncError'
Instance type for all SDK-thrown errors.
ZKsyncError.envelope: ErrorEnvelope
Categories (when to expect them)
Result style (try*) helpers
Every resource method has a try* sibling that never throws and returns a TryResult<T>.
try/catch.
Revert details (when transactions fail)
If the provider exposes revert data, the adapters will decode common error types and ABIs so you can branch on them:- The SDK always includes the 4-byte selector.
name/argsappear when decodable against known ABIs; coverage will expand over time.- When a revert implies “not ready yet,” you’ll typically see a
STATEerror with a clarifyingmessage.
Ethers & viem examples
Logging & observability
err.toJSON()returns a safe, structured object you can ship to logs/telemetry.- For local debugging, printing
errshows a compact, human-readable view (category, operation, context, optional revert/cause).