diff --git a/docs/docs/guides/accounts_migration_guide.md b/docs/docs/guides/accounts_migration_guide.md index 7f93aa5595f..03a320a9445 100644 --- a/docs/docs/guides/accounts_migration_guide.md +++ b/docs/docs/guides/accounts_migration_guide.md @@ -3,7 +3,7 @@ sidebar_position: 5 sidebar_label: Web3.eth.accounts --- -# Web3.eth.accounts Migration Guide +# Web3 eth accounts Migration Guide ## Breaking changes diff --git a/docs/docs/guides/net_migration_guide.md b/docs/docs/guides/net_migration_guide.md index daa638fa4d2..a9dee16f8b9 100644 --- a/docs/docs/guides/net_migration_guide.md +++ b/docs/docs/guides/net_migration_guide.md @@ -1,3 +1,8 @@ +--- +sidebar_position: 8 +sidebar_label: Web3.*.net +--- + # Web3 Net Migration guide ## Breaking Changes diff --git a/packages/web3-net/src/index.ts b/packages/web3-net/src/index.ts index 342cf6901bc..a4c1abb033d 100644 --- a/packages/web3-net/src/index.ts +++ b/packages/web3-net/src/index.ts @@ -15,6 +15,36 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ +/** + * The web3-net package allows you to interact with an Ethereum node’s network properties. + * + * ```ts + * import Net from 'web3-net'; + * + * const net = new Net(Net.givenProvider || 'ws://some.local-or-remote.node:8546'); + * // or using the web3 umbrella package + * import Web3 from 'web3'; + * const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); + * + * // -> web3.eth.net + * + * // get the ID of the network + * await web3.eth.net.getId(); + * > 5777n + * + * // get the peer count + * await web3.eth.net.getPeerCount(); + * > 0n + * + * // Check if the node is listening for peers + * await web3.eth.net.isListening(); + * > true + * ``` + */ + +/** + * + */ import { Net } from './net'; export * from './net'; diff --git a/packages/web3-net/src/net.ts b/packages/web3-net/src/net.ts index e432f41c0a9..8620cad0b04 100644 --- a/packages/web3-net/src/net.ts +++ b/packages/web3-net/src/net.ts @@ -21,18 +21,48 @@ import * as rpcMethodsWrappers from './rpc_method_wrappers'; import { Web3NetAPI } from './web3_net_api'; export class Net extends Web3Context { + /** + * Gets the current network ID + * @returns A Promise of the network ID. + * @example + * ```ts + * const net = new Net(Net.givenProvider || 'ws://some.local-or-remote.node:8546'); + * await net.getId(); + * > 1 + * ``` + */ public async getId( returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat, ) { return rpcMethodsWrappers.getId(this, returnFormat); } + /** + * Get the number of peers connected to. + * @returns A promise of the number of the peers connected to. + * @example + * ```ts + * const net = new Net(Net.givenProvider || 'ws://some.local-or-remote.node:8546'); + * await net.getPeerCount(); + * > 0 + * ``` + */ public async getPeerCount( returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat, ) { return rpcMethodsWrappers.getPeerCount(this, returnFormat); } + /** + * Check if the node is listening for peers + * @returns A promise of a boolean if the node is listening to peers + * @example + * ```ts + * const net = new Net(Net.givenProvider || 'ws://some.local-or-remote.node:8546'); + * await net.isListening(); + * > true + * ``` + */ public async isListening() { return rpcMethodsWrappers.isListening(this); }