@somnia-chain/markets-sdk / index / ContractRevertError
Class: ContractRevertError
Defined in: packages/sdk/src/errors.ts:245
A contract rejected the call — the SDK decodes the revert against the protocol's custom-error ABIs so the failure reads as its Solidity name.
Details
errorName is the contract's own error (e.g. "InsufficientBalance",
"MarketNotSettled", "ExpiredOrderMustBeCancelled") and args its
decoded parameters — that pair is what a caller branches on to decide
whether to cancel-then-retry, top up collateral, or give up.
Thrown on every revert path: send-time rejection, pre-send simulation, a
mined receipt with failed status, and eth_call reads.
Gotchas
errorName is not always populated. When the revert data doesn't match any
known error (a bare require string, an unknown selector, or no data at all)
it is undefined and reason/data carry whatever the node returned — so
branch with a fallback arm rather than assuming a name. The error is still
this class either way, so callers never face a raw viem error.
Example
import { ContractRevertError } from "@somnia-chain/markets-sdk";
try {
await trader.placeOrder(params);
} catch (e) {
if (e instanceof ContractRevertError && e.errorName === "ExpiredOrderMustBeCancelled") {
await trader.cancelExpiredOrders({ pool });
} else throw e;
}
Extends
Constructors
Constructor
new ContractRevertError(
fields,options?):ContractRevertError
Defined in: packages/sdk/src/errors.ts:259
Parameters
fields
errorName?
string
args?
readonly unknown[]
reason?
string
data?
string
address?
string
functionName?
string
options?
ErrorOptions
Returns
ContractRevertError
Overrides
SomniaMarketsError.constructor
Properties
errorName?
readonlyoptionalerrorName?:string
Defined in: packages/sdk/src/errors.ts:247
The decoded Solidity error name, or undefined when the revert didn't match a known error.
args?
readonlyoptionalargs?: readonlyunknown[]
Defined in: packages/sdk/src/errors.ts:249
Decoded arguments of the custom error, positionally, when errorName is set.
reason?
readonlyoptionalreason?:string
Defined in: packages/sdk/src/errors.ts:251
A plain require/revert string reason, when the revert carried one instead of a custom error.
data?
readonlyoptionaldata?:string
Defined in: packages/sdk/src/errors.ts:253
Raw revert data as returned by the node, when present.
address?
readonlyoptionaladdress?:string
Defined in: packages/sdk/src/errors.ts:255
The contract that reverted, when known.
functionName?
readonlyoptionalfunctionName?:string
Defined in: packages/sdk/src/errors.ts:257
The function that was called, when known.