Skip to main content

ethers

PropertyValue
Packageethers
Versions Covered>=6.0.0 <7.0.0
Contract Version1.0.0
Statusproduction
Last Verified2026-02-25
Maintainercorpus-team

Installation

npm install ethers

Covered Functions

This contract covers 2 function(s):

getBalance()

Gets account balance from blockchain

Import:

import { getBalance } from 'ethers';

Postconditions

What happens after calling this function:

🔴 ERROR - getbalance-rpc-error

Condition: RPC call fails (network down, rate limit, invalid address, node error)

Throws: Error with RPC error details and error code

Required Handling:

Caller MUST wrap provider.getBalance() in try-catch to handle RPC errors. Network failures, rate limits, and invalid addresses crash application if unhandled.

📖 Source


sendTransaction()

Sends transaction to blockchain

Import:

import { sendTransaction } from 'ethers';

Postconditions

What happens after calling this function:

🔴 ERROR - sendtransaction-error

Condition: transaction fails (insufficient gas, nonce error, network error, reverted)

Throws: Error with transaction failure details (gas estimation, nonce, revert reason)

Required Handling:

Caller MUST wrap sendTransaction() in try-catch to handle transaction errors. Gas estimation failures, nonce conflicts, and reverted transactions crash application if unhandled. Check error.code for specific error types.

📖 Source


Example: Proper Error Handling

import ethers from 'ethers';

async function example() {
try {
const result = await getBalance(/* args */);
// Handle success
return result;
} catch (error) {
// Handle error according to contract postconditions
console.error('Error:', error);
throw error;
}
}

See Also