Expand description
Error types for near-kit.
This module provides comprehensive error types for all near-kit operations.
§Error Hierarchy
Error— Main error type, returned by most operationsRpcError— RPC/network errors (connectivity, account not found, etc.)InvalidTxError— Transaction was rejected before execution (bad nonce, insufficient balance, expired, etc.)
Action errors (contract panics, missing keys, etc.) are not Err — the
transaction was accepted and executed, so the outcome is returned as
Ok(outcome) where outcome.is_failure() is true.
§Error Handling Examples
§Handling Transaction Errors
use near_kit::*;
let near = Near::testnet().build();
match near.transfer("bob.testnet", "1 NEAR").await {
Ok(outcome) if outcome.is_success() => {
println!("Success! Hash: {}", outcome.transaction_hash());
}
Ok(outcome) => {
// Transaction executed but an action failed — inspect the outcome
println!("Action failed: {:?}, gas used: {}", outcome.failure_message(), outcome.total_gas_used());
}
Err(Error::InvalidTx(e)) => {
// Transaction was rejected before execution (bad nonce, insufficient balance, etc.)
println!("Transaction rejected: {}", e);
}
Err(e) => return Err(e),
}§Checking Retryable Errors
use near_kit::RpcError;
fn should_retry(err: &RpcError) -> bool {
err.is_retryable()
}Enums§
- Error
- KeyStore
Error - Error during keystore operations.
- Parse
Amount Error - Error parsing a NEAR token amount.
- Parse
GasError - Error parsing a gas value.
- Parse
Hash Error - Error parsing a crypto hash.
- Parse
KeyError - Error parsing a public or secret key.
- RpcError
- RPC-specific errors.
- Signer
Error - Error during signing operations.
Type Aliases§
- Parse
Account IdError - Error parsing an account ID.