Socket
Socket
Sign inDemoInstall

web3-providers-http

Package Overview
Dependencies
47
Maintainers
2
Versions
384
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    web3-providers-http

Module to handle web3 RPC connections over HTTP.


Version published
Weekly downloads
403K
decreased by-16.01%
Maintainers
2
Install size
2.27 MB
Created
Weekly downloads
 

Package description

What is web3-providers-http?

The web3-providers-http package is a part of the Web3.js library that allows you to interact with Ethereum nodes using HTTP. It provides a way to send JSON-RPC requests to an Ethereum node over HTTP, making it possible to perform various blockchain-related operations such as querying blockchain data, sending transactions, and more.

What are web3-providers-http's main functionalities?

Connecting to an Ethereum Node

This feature allows you to connect to an Ethereum node using an HTTP provider. The code sample demonstrates how to create a new Web3 instance and connect it to a local Ethereum node running on port 8545.

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
console.log('Connected to Ethereum node:', web3.currentProvider.host);

Sending JSON-RPC Requests

This feature allows you to send JSON-RPC requests to the Ethereum node. The code sample demonstrates how to get the latest block number from the connected Ethereum node.

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
web3.eth.getBlockNumber().then(console.log);

Handling Errors

This feature allows you to handle errors that may occur when sending JSON-RPC requests. The code sample demonstrates how to catch and log errors when trying to get the latest block number.

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
web3.eth.getBlockNumber().then(console.log).catch(console.error);

Other packages similar to web3-providers-http

Changelog

Source

[1.2.8]

Added

  • Introduce review and release guidelines. (#3460)
  • Add EIP-1193 compatible provider to AbstractProvider interface. (#3499)
  • Add TypeScript definitions for contract methods and call. (#3454)
  • Update AbstractProvider and contract.methods TS definitions (#3521)
  • Add support for ENS contenthash methods. (#3392, #2782)

Changed

  • Change CI provider from Travis to GitHub Actions. (#3468)
  • Update web3-eth-abi ABICoder dependency. (#3490)
  • Update AbiCoder param formatting (#3522)
  • Improve code clarity of HttpProvider keepAlive option setting. (#3463)
  • Updated type definitions for Web3 HTTP Provider. (#3482)
  • Fix indentation of web3-eth documentation. (#3478)

Fixed

  • Fix intermittent CI build issues with dtslint. (#3479)
  • Fix WSS credentials Base64 encoding (for browser) (#3508)
  • Fire provider "error" and/or "end" events when Websocket provider disconnects. (#3485)
  • Remove web3-eth revert error return types to squash TS compilation errors. (#3496)
  • Backfill event subscriptions when WS connection dropped across multiple blocks. (#3491)
  • Stop swallowing errors when WS connection has died after exhausting reconnection attempts. (#3492)
  • Fix setContenthash docs formatting (#3511)

Readme

Source

web3-providers-http

NPM Package Dependency Status Dev Dependency Status

This is a sub-package of web3.js.

This is a HTTP provider for web3.js.

Please read the documentation for more.

Installation

Node.js

npm install web3-providers-http

In the Browser

Build running the following in the web3.js repository:

npm run-script build-all

Then include dist/web3-providers-http.js in your html file. This will expose the Web3HttpProvider object on the window object.

Usage

// in node.js
var http = require('http');
var Web3HttpProvider = require('web3-providers-http');

var options = {
    keepAlive: true,
    timeout: 20000, // milliseconds,
    headers: [{name: 'Access-Control-Allow-Origin', value: '*'},{...}],
    withCredentials: false,
    agent: {http: http.Agent(...), baseUrl: ''}
};

var provider = new Web3HttpProvider('http://localhost:8545', options);

Types

All the TypeScript typings are placed in the types folder.

FAQs

Last updated on 20 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc