-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(glossary): updated glossary #7168
Changes from 1 commit
622dace
0a97046
ec60406
a5cb2d0
273e083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,3 +108,85 @@ contract Test { | |
} | ||
] | ||
``` | ||
|
||
## Proxy | ||
|
||
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. Understanding how to set up and use proxies with `HttpProvider` and `WebsocketProvider` in Web3.js is crucial for building robust and secure blockchain applications. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to be careful about saying that setting something up properly is crucial for security without providing any additional context or information about how to actually set things up so they are secure. Can we link to some documentation that explains how to securely configure a proxy? |
||
|
||
## HttpProvider | ||
`HttpProvider` 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. Proper security measures are crucial when exposing HTTP endpoints. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of the word "essential" is confusing to me here. What are you trying to say? I would also be careful about bringing up the idea of crucial security measures without providing additional context about the specific measures that need to be taken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback, I will work on this |
||
|
||
```javascript title='HttpProvider example' | ||
SantiagoDevRel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const Web3 = require('web3'); | ||
EmmanuelOluwafemi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); | ||
``` | ||
|
||
## WebSocketProvider | ||
`WebSocketProvider` 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. | ||
|
||
```javascript title='WebSocketProvider example' | ||
const Web3 = require('web3'); | ||
EmmanuelOluwafemi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8546')); | ||
``` | ||
|
||
## Events | ||
|
||
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). | ||
|
||
#### Example | ||
|
||
```solidity title='Event in solidity' | ||
contract MyContract { | ||
event Transfer(address indexed from, address indexed to, uint value); | ||
|
||
function transfer(address recipient, uint amount) public { | ||
// ... transfer logic ... | ||
emit Transfer(msg.sender, recipient, amount); | ||
} | ||
} | ||
``` | ||
|
||
```javascript title='Event in web3.js' | ||
const Web3 = require('web3'); | ||
EmmanuelOluwafemi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const MyContract = require('./MyContract.json'); // Assuming ABI is loaded | ||
|
||
const web3 = new Web3('wss://mainnet.infura.io/v3/YOUR_INFURA_ID'); // Replace with your provider URL | ||
const contractAddress = '0x...'; // Replace with your contract address | ||
|
||
const myContract = new web3.eth.Contract(MyContract.abi, contractAddress); | ||
|
||
const transferEvent = myContract.events.Transfer(); // Access the Transfer event | ||
|
||
transferEvent.on('data', (event) => { | ||
console.log('Transfer Event:', event); | ||
// Process the event data (from, to, value) | ||
}); | ||
``` | ||
|
||
## Event logs | ||
|
||
`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. | ||
|
||
#### Example | ||
|
||
```javascript title='Event Log in web3.js' | ||
SantiagoDevRel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const Web3 = require('web3'); | ||
EmmanuelOluwafemi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID'); | ||
|
||
const options = { | ||
fromBlock: 0, | ||
toBlock: 'latest', | ||
address: '0xYourContractAddress', | ||
topics: [ | ||
web3.utils.sha3('Transfer(address,address,uint256)') | ||
] | ||
}; | ||
|
||
web3.eth.getPastLogs(options) | ||
.then((logs) => { | ||
console.log(logs); | ||
}) | ||
.catch((error) => { | ||
console.error('Error retrieving logs:', error); | ||
}); | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danforbes what do you suggest for keeping glossary section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a good glossary can be extremely helpful, but it's important that it's managed carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I will work on this