Socket
Socket
Sign inDemoInstall

web3-providers-http

Package Overview
Dependencies
3
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.25 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.5]

Added

  • eth_requestAccounts as requestAccounts added to web3-eth package (#3219)
  • sha3Raw and soliditySha3Raw added to web3-utils package (#3226)
  • eth_getProof as getProof added to web3-eth package (#3220)
  • BN and BigNumber objects are now supported by the abi.encodeParameter(s) method (#3238)
  • getPendingTransactions added to web3-eth package (#3239)
  • Revert instruction handling added which can get activated with the handleRevert module property (#3248)
  • The receipt does now exist as property on the error object for transaction related errors (#3259)
  • internalType added to AbiInput TS interface in web3-utils (#3279)
  • Agent option added to the HttpProvider options (#2980)

Changed

  • eth-lib dependency updated (0.2.7 => ^0.2.8) (#3242)

Fixed

  • Fix crash when decoding events with identical signatures, differently indexed args (#3272)
  • Fix user supplied callback not fired in eth.accounts.signTransaction (#3283)
  • Fix minified bundle (#3256)
  • defaultBlock property handling fixed (#3247)
  • clearSubscriptions does no longer throw an error if no running subscriptions do exist (#3246)
  • callback type definition for Accounts.signTransaction fixed (#3280)
  • fix: export bloom functions on the index.js
  • Prefer receipt status to code availability on contract deployment (#3298)

Readme

Source

web3-providers-http

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 27 Jan 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