Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 496ed93

Browse files
author
Dan Forbes
authored
Restructure Docs (#7298)
* Restructure Docs * Set tab-size to 2 for Docs
1 parent 7c207b8 commit 496ed93

File tree

79 files changed

+3460
-3461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3460
-3461
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ yarn add web3
4343

4444
## Migration Guide
4545

46-
- [Migration Guide from Web3.js 1.x to 4.x](https://docs.web3js.org/guides/web3_upgrade_guide/x/)
46+
- [Migration Guide from Web3.js 1.x to 4.x](https://docs.web3js.org/guides/web3_upgrade_guide/index)
4747
Breaking changes are listed in migration guide and its first step for migrating from Web3.js 1.x to 4.x. If there is any question or discussion feel free to ask in [Discord](https://discord.gg/yjyvFRP), and in case of any bug or new feature request [open issue](https://github.com/web3/web3.js/issues/new) or create a pull request for [contributions](https://github.com/web3/web3.js/blob/4.x/.github/CONTRIBUTING.md).
4848

4949
## Useful links
@@ -76,18 +76,18 @@ yarn add web3
7676

7777
## Package.json Scripts
7878

79-
| Script | Description |
80-
| ---------------- |--------------------------------------------------------------------|
81-
| clean | Uses `rimraf` to remove `dist/` |
82-
| build | Uses `tsc` to build all packages |
83-
| lint | Uses `eslint` to lint all packages |
84-
| lint:fix | Uses `eslint` to check and fix any warnings |
85-
| format | Uses `prettier` to format the code |
86-
| test | Uses `jest` to run unit tests in each package |
87-
| test:integration | Uses `jest` to run tests under `/test/integration` in each package |
88-
| test:unit | Uses `jest` to run tests under `/test/unit` in each package |
89-
| test:manual:long-connection-ws | Runs manual tests for keeping a long WebSocket connection |
90-
| test:manual | Runs manual tests under `test/manual` in the web3 package |
79+
| Script | Description |
80+
| ------------------------------ | ------------------------------------------------------------------ |
81+
| clean | Uses `rimraf` to remove `dist/` |
82+
| build | Uses `tsc` to build all packages |
83+
| lint | Uses `eslint` to lint all packages |
84+
| lint:fix | Uses `eslint` to check and fix any warnings |
85+
| format | Uses `prettier` to format the code |
86+
| test | Uses `jest` to run unit tests in each package |
87+
| test:integration | Uses `jest` to run tests under `/test/integration` in each package |
88+
| test:unit | Uses `jest` to run tests under `/test/unit` in each package |
89+
| test:manual:long-connection-ws | Runs manual tests for keeping a long WebSocket connection |
90+
| test:manual | Runs manual tests under `test/manual` in the web3 package |
9191

9292
[npm-url]: https://npmjs.org/package/web3
9393
[downloads-image]: https://img.shields.io/npm/dm/web3?label=npm%20downloads

docs/docs/glossary/index.md

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ sidebar_label: '📖 Glossary'
44
title: Glossary
55
---
66

7-
87
## Provider
98

109
In web3.js, a `provider` is an object responsible for enabling connectivity with the Ethereum network in various ways. Providers facilitate the connection of your web application to an Ethereum node, different provider types are available in web3.js(HTTP, WebSocket and IPC), each with its own features and use cases. **It's important to note that a provider itself only provides read-only access to the blockchain.** It does not use any private keys or accounts for interaction. This read-only functionality is particularly useful for querying data and making calls to the blockchain without the need for private key authorization.
@@ -13,12 +12,10 @@ In web3.js, a `provider` is an object responsible for enabling connectivity with
1312

1413
In web3.js, an `account` allows you to perform operations on the blockchain, such as sending transactions, signing data, and interacting with contracts. It serves as the key component for **using a private key** directly to execute various blockchain operations. In other libraries, this concept is often referred to as a `signer`. This versatility in terminology doesn't change its fundamental purpose, providing a secure and straightforward means to manage Ethereum-related operations.
1514

16-
1715
## Wallet
1816

1917
A `wallet` in web3.js can store multiple `accounts`. This feature allows you to manage various private keys for different operations. When using methods such as `web3.eth.sendTransaction()` or `web3.eth.contract.methods.doSomething().send({})`, the web3.js library handles these transactions using the wallet accounts under the hood. Essentially, the wallet makes it easier to coordinate multiple accounts for smoother Ethereum operations.
2018

21-
2219
## Contract
2320

2421
The `Contract` class is an important class in the `web3-eth-contract` package, also available in the `web3` package. It serves as an abstraction representing a connection to a specific contract on the Ethereum Network, enabling applications to interact with it as a typical JavaScript object. Through the `Contract` class, you can execute functions and listen to events associated with the smart contract (e.g, `contract.methods.doSomething().call()`)
@@ -82,30 +79,39 @@ contract Test {
8279

8380
```json title='Resulting JSON ABI'
8481
[
85-
{
86-
"type": "constructor",
87-
"stateMutability": "nonpayable",
88-
"inputs": [{"internalType":"uint256","name":"testInt","type":"uint256"}],
89-
},
90-
{
91-
"type": "event",
92-
"name": "Event",
93-
"inputs": [{"indexed":true,"internalType":"uint256","name":"b","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"c","type":"bytes32"}],
94-
"anonymous": false,
95-
},
96-
{
97-
"type": "event",
98-
"name": "Event2",
99-
"inputs": [{"indexed":true,"internalType":"uint256","name":"b","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"c","type":"bytes32"}],
100-
"anonymous": false,
101-
},
102-
{
103-
"type": "function",
104-
"name": "foo",
105-
"stateMutability": "nonpayable",
106-
"inputs": [{"internalType":"uint256","name":"b","type":"uint256"},{"internalType":"bytes32","name":"c","type":"bytes32"}],
107-
"outputs": [{"internalType":"address","name":"","type":"address"}],
108-
}
82+
{
83+
"type": "constructor",
84+
"stateMutability": "nonpayable",
85+
"inputs": [{ "internalType": "uint256", "name": "testInt", "type": "uint256" }]
86+
},
87+
{
88+
"type": "event",
89+
"name": "Event",
90+
"inputs": [
91+
{ "indexed": true, "internalType": "uint256", "name": "b", "type": "uint256" },
92+
{ "indexed": false, "internalType": "bytes32", "name": "c", "type": "bytes32" }
93+
],
94+
"anonymous": false
95+
},
96+
{
97+
"type": "event",
98+
"name": "Event2",
99+
"inputs": [
100+
{ "indexed": true, "internalType": "uint256", "name": "b", "type": "uint256" },
101+
{ "indexed": false, "internalType": "bytes32", "name": "c", "type": "bytes32" }
102+
],
103+
"anonymous": false
104+
},
105+
{
106+
"type": "function",
107+
"name": "foo",
108+
"stateMutability": "nonpayable",
109+
"inputs": [
110+
{ "internalType": "uint256", "name": "b", "type": "uint256" },
111+
{ "internalType": "bytes32", "name": "c", "type": "bytes32" }
112+
],
113+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }]
114+
}
109115
]
110116
```
111117

@@ -123,6 +129,7 @@ const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
123129
```
124130

125131
## WebSocketProvider
132+
126133
[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.
127134

128135
```javascript title='WebSocketProvider example'
@@ -138,13 +145,14 @@ The `Events` class in Web3.js is a crucial part of the library that enables deve
138145

139146
```solidity title='Event in solidity'
140147
contract MyContract {
141-
event Transfer(address indexed from, address indexed to, uint value);
148+
event Transfer(address indexed from, address indexed to, uint256 value);
142149
143-
function transfer(address recipient, uint amount) public {
144-
// ... transfer logic ...
145-
emit Transfer(msg.sender, recipient, amount);
146-
}
150+
function transfer(address recipient, uint256 amount) public {
151+
// ... transfer logic ...
152+
emit Transfer(msg.sender, recipient, amount);
153+
}
147154
}
155+
148156
```
149157

150158
```javascript title='Event in web3.js'
@@ -158,9 +166,9 @@ const myContract = new web3.eth.Contract(MyContract.abi, contractAddress);
158166

159167
const transferEvent = myContract.events.Transfer(); // Access the Transfer event
160168

161-
transferEvent.on('data', (event) => {
162-
console.log('Transfer Event:', event);
163-
// Process the event data (from, to, value)
169+
transferEvent.on('data', event => {
170+
console.log('Transfer Event:', event);
171+
// Process the event data (from, to, value)
164172
});
165173
```
166174

@@ -190,4 +198,5 @@ web3.eth.getPastLogs(options)
190198
.catch((error) => {
191199
console.error('Error retrieving logs:', error);
192200
});
193-
`
201+
`
202+
```
File renamed without changes.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
slug: /
3+
sidebar_position: 1
4+
sidebar_label: Introduction
5+
---
6+
7+
# Introduction
8+
9+
Web3.js is a robust and flexible collection of **TypeScript and JavaScript** libraries that allows developers to interact with local or remote [Ethereum](https://ethereum.org/en/) nodes (or **any EVM-compatible blockchain**) over **HTTP, IPC or WebSocket** connections. It is a powerful and efficient toolkit for crafting applications within the Ethereum ecosystem and beyond.
10+
11+
This documentation is the entrypoint to Web3.js for developers. It covers [basic](/guides/getting_started/quickstart) and [advanced](/guides/smart_contracts/mastering_smart_contracts) usage with examples, and includes comprehensive [API documentation](/api) as well as guides for common tasks, like [upgrading](/guides/web3_upgrade_guide) from older versions.
12+
13+
## Features of Web3.js v4
14+
15+
- Flexible
16+
- ECMAScript (ESM) and CommonJS (CJS) builds
17+
- [Plugins](/guides/web3_plugin_guide/) for extending functionality
18+
- Efficient
19+
- Modular, [package](/#packages)-based design reduces unneeded dependencies
20+
- [Tree shakable with ESM](/guides/advanced/tree_shaking)
21+
- Use of native [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) (instead of large [BigNumber](https://mikemcl.github.io/bignumber.js/) libraries)
22+
- Efficient ABI [encoding](/api/web3-eth-abi/function/encodeFunctionCall) & [decoding](/api/web3-eth-abi/function/decodeParameter)
23+
- Developer-Friendly
24+
- [Dynamic contract types](/guides/smart_contracts/infer_contract_types/) & full API in TypeScript
25+
- Custom output [formatters](https://docs.web3js.org/api/web3-utils/function/format)
26+
- In compliance with the [Ethereum JSON-RPC Specification](https://ethereum.github.io/execution-apis/api-documentation/)
27+
28+
## Using These Docs
29+
30+
There is a lot to learn about Web3.js! Here are some tips for developers of different skill levels. Remember, you can always [reach out directly](/guides/feedback/#urgent-questions-or-concerns) with Discord or Twitter if you're feeling stuck.
31+
32+
### For Beginner Web3.js Developers
33+
34+
New Web3.js developers should proceed to the [Quickstart](/guides/getting_started/quickstart) section to learn how to get started with Web3.js. Once you understand the basics, you may want to consider learning more about [providers](/guides/web3_providers_guide/), [wallets and accounts](/guides/wallet), [smart contracts](/guides/smart_contracts/smart_contracts_guide), and how to [use Web3.js with the Hardhat development environment](/guides/hardhat_tutorial).
35+
36+
### For Intermediate & Advanced Web3.js Developers
37+
38+
If you're already familiar with Ethereum and Web3.js development, you may want to review the Web3.js [package structure](#packages--plugins) and proceed directly to the [package-level documentation](/libdocs/ABI) and [API documentation](/api). Application developers may wish to review the [Web3.js configuration guide](/guides/web3_config) or learn how to use Web3.js with tools like the [MetaMask](/guides/dapps/metamask-react) wallet or the [WalletConnect](/guides/dapps/web3_modal_guide) wallet selection modal. Don't forget to review the [list of available plugins](https://web3js.org/plugins) or even [learn how to build your own Web3.js plugin](/guides/web3_plugin_guide/plugin_authors)!
39+
40+
## Packages & Plugins
41+
42+
Web3.js is a modular collection of packages, each of which serves a specific needs. This means developers don't need to install the entire Web3 library for most use cases. Instead, necessary packages are selectively installed for a more efficient development experience. Here is an overview of a selection of available packages:
43+
44+
- [**Web3Eth:**](/libdocs/Web3Eth) The `web3-eth` package is the entrypoint to Web3.js - it's the control center for managing interactions with Ethereum and other EVM-compatible networks.
45+
46+
- [**Net:**](/libdocs/Net) The `web3-net` package provides discovery and interactions for an **Ethereum node's network properties.**
47+
48+
- [**Accounts:**](/libdocs/Accounts) The `web3-eth-accounts` package has tools for creating Ethereum accounts and the **secure signing** of transactions and data.
49+
50+
- [**Personal:**](/libdocs/Personal) Use `web3-eth-personal` for **direct communication about your accounts with the Ethereum node**, which streamlines account management during development.
51+
52+
**NOTE:** _For enhanced security in production and when interacting with public nodes, consider using `web3-eth-accounts` for local signing operations, which keeps your private keys and sensitive information secure on your local machine_
53+
54+
- [**Utils:**](/libdocs/Utils) The `web3-utils` package provides helpers to perform a range of essential Ethereum development tasks, including **converting data formats, checking addresses, encoding and decoding data, hashing, handling numbers, and much more.**.
55+
56+
- [**Contract:**](/libdocs/Contract) The `web3-eth-contract` package makes it easy to **interact with smart contracts through JavaScript or TypeScript,** which streamlines the development process and makes it less error-prone.
57+
58+
- [**ABI:**](/libdocs/ABI) The `web3-eth-abi` package simplifies decoding logs and parameters, encoding function calls and signatures, and inferring types for efficient Ethereum **smart contract interactions.**
59+
60+
- [**ENS:**](/libdocs/ENS) The `web3-eth-ens` package makes it easy for developers to communicate with the **Ethereum Name Service (ENS).**
61+
62+
- [**Iban:**](/libdocs/Iban) The `web3-eth-iban` package allows you to switch between **Ethereum addresses and special banking-like addresses** (IBAN or BBAN) and simplifies conversion between the types.
63+
64+
### Additional Supporting Packages
65+
66+
- [**Web3 Core:**](/api/web3-core) subscriptions, request management, and configuration used by other Web3 packages
67+
68+
- [**Web3 Types:**](/api/web3-types) data structures, objects, interfaces and types used by Web3
69+
70+
- [**Web3 Validator:**](/api/web3-validator) runtime type validation against predefined types or custom schemas
71+
72+
- [**Web3 Errors:**](/api/web3-errors) error codes and common error classes that are used by other Web3 packages
73+
74+
- [**Web3 RPC Methods:**](/api/web3/namespace/rpcMethods) functions for making RPC requests to Ethereum using a given provider
75+
76+
### Plugins
77+
78+
Web3.js supports [plugins](/guides/web3_plugin_guide/), which are another way to encapsulate capabilities that support a specific need. There are plugins that exist to support native features, like those described by [EIPs](https://eips.ethereum.org/) as well as plugins that are designed to support specific smart contracts, middleware, or even other Ethereum-compatible networks. Visit the [Web3.js plugins homepage](https://web3js.org/plugins) to view a list of the most important Web3.js plugins, which includes:
79+
80+
- [EIP-4337 (Account Abstraction) Plugin](https://www.npmjs.com/package/@chainsafe/web3-plugin-eip4337)
81+
82+
- [EIP-4844 (Blob Transactions) Plugin](https://www.npmjs.com/package/web3-plugin-blob-tx)
83+
84+
- [zkSync Plugin](https://www.npmjs.com/package/web3-plugin-zksync)
85+
86+
## Advantages Over Other Libraries
87+
88+
- **Extensive Documentation and Community**: Web3.js is one of the most established Ethereum libraries, which means it benefits from extensive documentation and a large, active community. Web3.js is widely adopted and has been thoroughly tested in various production environments, and is compatible with a broad range of other tools and services in the Ethereum ecosystem.
89+
90+
- **Modular Design**: Web3.js is designed to be modular, which allows developers to use specific packages according to their needs. This leads to smaller bundle sizes and faster load times for web applications.
91+
92+
- **Active Development and Support**: Web3.js sees regular updates and active development. This support is crucial for developers needing assurance that the library they're using will keep pace with the evolving Ethereum landscape.

0 commit comments

Comments
 (0)