Skip to content
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

add comment for web-rpc-methods package #7429

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/web3-rpc-methods/src/net_rpc_methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,46 @@ GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3RequestManager } from 'web3-core';
import { Web3NetAPI } from 'web3-types';

/**
* Fetches the network ID of the current Ethereum network.
* This corresponds to the `net_version` RPC call.
* @param requestManager - An instance of `Web3RequestManager` to send the RPC request.
* @returns A Promise that resolves to the network ID as a string.
*/
export async function getId(requestManager: Web3RequestManager<Web3NetAPI>) {
return requestManager.send({
method: 'net_version',
params: [],
});
}

/**
* Fetches the number of connected peers to the Ethereum network.
* This corresponds to the `net_peerCount` RPC call.
* @param requestManager - An instance of `Web3RequestManager` to send the RPC request.
* @returns A Promise that resolves to the peer count as a hexadecimal string.
*/
export async function getPeerCount(requestManager: Web3RequestManager<Web3NetAPI>) {
return requestManager.send({
method: 'net_peerCount',
params: [],
});
}

/**
* Checks if the Ethereum client is currently listening for network connections.
* This corresponds to the `net_listening` RPC call.
* @param requestManager - An instance of `Web3RequestManager` to send the RPC request.
* @returns A Promise that resolves to a boolean indicating if the client is listening.
*/
export async function isListening(requestManager: Web3RequestManager<Web3NetAPI>) {
return requestManager.send({
method: 'net_listening',
params: [],
});
}