Skip to content

Commit 389c7da

Browse files
committed
Module 33 Coplete
1 parent 3abd133 commit 389c7da

File tree

2 files changed

+217
-0
lines changed

2 files changed

+217
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# What are Signers?
2+
3+
In Ethers.js, a **Signer** represents an entity that can sign transactions and messages. Signers are used to send transactions, interact with smart contracts, and authenticate actions. Unlike Providers, which read data from the blockchain, Signers perform write operations by creating and signing transactions.
4+
5+
---
6+
7+
## Wallet Signer
8+
The **Wallet Signer** is a representation of a private key in Ethers.js. It can be used to sign transactions and messages or interact with smart contracts. Wallets can be created in several ways:
9+
10+
- From a private key: `new ethers.Wallet(privateKey)`
11+
- From a mnemonic phrase: `ethers.Wallet.fromMnemonic(mnemonic)`
12+
- From a JSON wallet: `ethers.Wallet.fromEncryptedJson(json, password)`
13+
14+
---
15+
16+
## JsonRPC Signer
17+
The **JsonRPC Signer** is associated with a JSON-RPC provider. It allows signing transactions and interacting with blockchain accounts managed by the connected node.
18+
19+
Example:
20+
```javascript
21+
const provider = new ethers.providers.JsonRpcProvider();
22+
const signer = provider.getSigner();
23+
```
24+
25+
---
26+
27+
## Signer Class and Member Functions
28+
The `Signer` class is the base for all Signer objects. Common methods include:
29+
30+
- `getAddress()`: Returns the address of the signer.
31+
- `signMessage(message)`: Signs a message.
32+
- `sendTransaction(transaction)`: Sends a signed transaction.
33+
- `connect(provider)`: Connects the signer to a provider.
34+
- `signTransaction(transaction)`: Signs a raw transaction object.
35+
36+
---
37+
38+
## Ethers.js Wallet Class and Member Functions
39+
The `Wallet` class in Ethers.js is an extension of the `Signer` class. It represents a private key and provides the following functions:
40+
41+
- `getAddress()`: Returns the wallet's address.
42+
- `signMessage(message)`: Signs a message using the wallet's private key.
43+
- `signTransaction(transaction)`: Signs a transaction object.
44+
- `sendTransaction(transaction)`: Sends a signed transaction.
45+
- `encrypt(password[, options])`: Encrypts the wallet's private key with a password.
46+
47+
---
48+
49+
## VoidSigner
50+
The **VoidSigner** is a placeholder signer. It is used when you need to represent an address without having access to its private key. This is useful for read-only operations.
51+
52+
Example:
53+
```javascript
54+
const voidSigner = new ethers.VoidSigner(address, provider);
55+
```
56+
57+
---
58+
59+
## Interacting with Externally Owned Accounts (EOA)
60+
Externally Owned Accounts (EOAs) are accounts controlled by private keys, as opposed to smart contract accounts. Signers are essential for interacting with EOAs because they:
61+
62+
- Authenticate the account holder.
63+
- Sign transactions to be sent to the blockchain.
64+
- Enable interaction with smart contracts on behalf of the account.
65+
66+
Typical interactions include:
67+
- Sending ETH or tokens.
68+
- Invoking smart contract functions.
69+
- Signing off-chain messages for authentication or data integrity.

0 commit comments

Comments
 (0)