|
| 1 | +# What are Providers? |
| 2 | + |
| 3 | +In the Ethers.js library, a **Provider** is an abstraction that provides a connection to the Ethereum network. It allows developers to query blockchain data, interact with smart contracts, and send transactions. Providers do not manage private keys or sign transactions but focus on retrieving and broadcasting blockchain data. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Ethers.js Provider API Overview |
| 8 | + |
| 9 | +Ethers.js offers various types of providers to connect to the Ethereum network through different nodes and APIs. These providers enable interactions with Ethereum data, including accounts, blocks, transactions, and logs. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Provider Account Methods |
| 14 | +- `getBalance(address[, blockTag])` |
| 15 | +- `getTransactionCount(address[, blockTag])` |
| 16 | +- `getCode(address[, blockTag])` |
| 17 | +- `getStorageAt(address, position[, blockTag])` |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +### Blocks Methods |
| 22 | +- `getBlock(blockHashOrBlockTag)` |
| 23 | +- `getBlockWithTransactions(blockHashOrBlockTag)` |
| 24 | +- `getBlockNumber()` |
| 25 | +- `getGasPrice()` |
| 26 | +- `getFeeData()` |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +### Ethereum Naming Service (ENS) Methods |
| 31 | +- `resolveName(name)` |
| 32 | +- `lookupAddress(address)` |
| 33 | +- `getAvatar(name)` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +### EnsResolver |
| 38 | +An object to interact with resolved ENS names: |
| 39 | +- `getAddress()` |
| 40 | +- `getContentHash()` |
| 41 | +- `getText(key)` |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +### Logs Methods |
| 46 | +- `getLogs(filter)` |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +### Network Status Methods |
| 51 | +- `getNetwork()` |
| 52 | +- `getChainId()` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +### Transactions Methods |
| 57 | +- `getTransaction(transactionHash)` |
| 58 | +- `getTransactionReceipt(transactionHash)` |
| 59 | +- `waitForTransaction(transactionHash[, confirmations[, timeout]])` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +### Event Emitter Methods |
| 64 | +- `on(eventName, listener)` |
| 65 | +- `once(eventName, listener)` |
| 66 | +- `off(eventName[, listener])` |
| 67 | +- `removeAllListeners([eventName])` |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +### Inspection Methods |
| 72 | +- `listAccounts()` |
| 73 | +- `listenerCount(eventName)` |
| 74 | +- `listeners(eventName)` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## BaseProvider |
| 79 | +Base class for all providers in Ethers.js. Implements common methods for querying blockchain data. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## JsonRpcProvider |
| 84 | +Connects to the Ethereum network using JSON-RPC over HTTP or HTTPS. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## JsonRpcSigner |
| 89 | +Manages signing transactions using private keys. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## JsonRpcUncheckedSigner |
| 94 | +Similar to `JsonRpcSigner` but skips transaction nonce management. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## StaticJsonRpcProvider |
| 99 | +A variation of `JsonRpcProvider` with static network configuration. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Node-Specific Methods |
| 104 | +Node-specific provider extensions, such as `IpcProvider` and `WebSocketProvider`, allow enhanced interactions depending on the environment. |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## API Providers |
| 109 | + |
| 110 | +### EtherscanProvider |
| 111 | +Uses the Etherscan API to access Ethereum data. |
| 112 | + |
| 113 | +### InfuraProvider |
| 114 | +Connects via the Infura API for scalable Ethereum access. |
| 115 | + |
| 116 | +### AlchemyProvider |
| 117 | +Utilizes the Alchemy API for blockchain data. |
| 118 | + |
| 119 | +### CloudflareProvider |
| 120 | +Provides Ethereum data via Cloudflare's service. |
| 121 | + |
| 122 | +### PocketProvider |
| 123 | +Uses Pocket Network to fetch Ethereum data. |
| 124 | + |
| 125 | +### AnkrProvider |
| 126 | +Connects through the Ankr API for reliable access to Ethereum. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Other Providers |
| 131 | + |
| 132 | +### FallbackProvider |
| 133 | +Combines multiple providers for reliability and redundancy. |
| 134 | + |
| 135 | +### IpcProvider |
| 136 | +Connects to the Ethereum network using Inter-Process Communication (IPC). |
| 137 | + |
| 138 | +### JsonRpcBatchProvider |
| 139 | +Allows batch processing of JSON-RPC requests. |
| 140 | + |
| 141 | +### UrlJsonRpcProvider |
| 142 | +Simplifies connection setup using a URL endpoint. |
| 143 | + |
| 144 | +### Web3Provider |
| 145 | +Wraps a web3-compatible provider for Ethereum interactions. |
| 146 | + |
| 147 | +### WebSocketProvider |
| 148 | +Provides a persistent WebSocket connection for real-time updates. |
0 commit comments