You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/docs/glossary/index.md
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,3 +108,86 @@ contract Test {
108
108
}
109
109
]
110
110
```
111
+
112
+
## Proxy
113
+
114
+
A `proxy` in Web3.js serves as an intermediary between your application and an Ethereum node, **facilitating communication** by **forwarding requests and responses**. Configuring a proxy can help overcome network restrictions, enhance security, and improve load balancing. You can set up a proxy using either HttpProvider or WebSocketProvider in Web3.js.
115
+
116
+
## HttpProvider
117
+
118
+
[HttpProvider](https://docs.web3js.org/guides/web3_providers_guide/#http-provider) in Web3.js connects an application to an Ethereum node over HTTP. It allows for sending transactions, reading blockchain data, and interacting with smart contracts. You create a Web3 instance with the node’s URL to establish the connection. It’s essential for DApps needing blockchain interaction but can block the event loop, so alternatives like `WebSocketProvider` might be used for better performance when real-time communication is needed.
[WebSocketProvider](https://docs.web3js.org/guides/web3_providers_guide/#websocket-provider) in Web3.js connects your application to an Ethereum node via WebSocket, enabling real-time and asynchronous communication. This provider is ideal for applications needing real-time updates, such as new blocks or smart contract events. It offers better performance for high-throughput applications compared to `HttpProvider`. Ensure secure connections with `wss://` for exposed endpoints. Handle reconnections gracefully for reliable operation.
The `Events` class in Web3.js is a crucial part of the library that enables developers to interact with and listen for events emitted by smart contracts on the Ethereum network. Events in **smart contracts** are similar to `logs` or `messages` that the **contract emits to notify** external applications about specific actions or state changes. Web3.js provides a comprehensive set of tools to handle these events, making it possible to build responsive and interactive decentralized applications (dApps).
136
+
137
+
#### Example
138
+
139
+
```solidity title='Event in solidity'
140
+
contract MyContract {
141
+
event Transfer(address indexed from, address indexed to, uint value);
142
+
143
+
function transfer(address recipient, uint amount) public {
144
+
// ... transfer logic ...
145
+
emit Transfer(msg.sender, recipient, amount);
146
+
}
147
+
}
148
+
```
149
+
150
+
```javascript title='Event in web3.js'
151
+
import { Web3 } from'web3';
152
+
constMyContract=require('./MyContract.json'); // Assuming ABI is loaded
153
+
154
+
constweb3=newWeb3('wss://mainnet.infura.io/v3/YOUR_INFURA_ID'); // Replace with your provider URL
155
+
constcontractAddress='0x...'; // Replace with your contract address
consttransferEvent=myContract.events.Transfer(); // Access the Transfer event
160
+
161
+
transferEvent.on('data', (event) => {
162
+
console.log('Transfer Event:', event);
163
+
// Process the event data (from, to, value)
164
+
});
165
+
```
166
+
167
+
## Event logs
168
+
169
+
`Logs` in Web3.js are a part of **Ethereum transactions** that contain **information about events triggered** within smart contracts. They provide a way to record and retrieve significant occurrences within the blockchain. `Event logs` are particularly useful for tracking changes, and debugging.
0 commit comments