Skip to main content

Module error

Module error 

Source
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 operations
    • RpcError — 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
KeyStoreError
Error during keystore operations.
ParseAmountError
Error parsing a NEAR token amount.
ParseGasError
Error parsing a gas value.
ParseHashError
Error parsing a crypto hash.
ParseKeyError
Error parsing a public or secret key.
RpcError
RPC-specific errors.
SignerError
Error during signing operations.

Type Aliases§

ParseAccountIdError
Error parsing an account ID.