near-kit converts cryptic RPC JSON errors into typed JavaScript Error classes. You can catch these errors and handle them logically.
The Error Hierarchy
All errors extendNearError. You can check for specific types using instanceof.
Error Types
FunctionCallError
FunctionCallError
Thrown when a smart contract call fails (panics or runs out of gas).Properties:
panic: The panic message from the contractlogs: Any logs emitted before the failure
AccountDoesNotExistError
AccountDoesNotExistError
Thrown when trying to interact with an account that doesn’t exist.Properties:
accountId: The account that wasn’t found
NetworkError
NetworkError
Thrown when there’s a network or RPC issue.Properties:
retryable: Whether it’s safe to retrystatusCode: HTTP status code (if applicable)
InsufficientBalanceError
InsufficientBalanceError
Thrown when an account doesn’t have enough NEAR for the operation.Properties:
accountId: The account with insufficient balancerequired: Amount neededavailable: Amount available
InvalidNonceError
InvalidNonceError
Thrown when a transaction’s nonce is stale (usually from concurrent transactions).
Panic Messages
When a contract fails, the most important info is the Panic Message.near-kit extracts this from the deep RPC response and puts it right on error.panic.
Common panics include:
ERR_NOT_ENOUGH_FUNDSERR_INVALID_ARGUMENTSmart contract panicked: ...