Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/abstract-provider

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/abstract-provider

An Abstract Class for describing an Ethereum Provider for ethers.

  • 5.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
922K
decreased by-7.58%
Maintainers
1
Weekly downloads
 
Created

What is @ethersproject/abstract-provider?

@ethersproject/abstract-provider is a part of the ethers.js library, which provides a collection of utilities for interacting with the Ethereum blockchain. This specific package defines the abstract interface for a provider, which is responsible for communicating with the Ethereum network. It includes methods for querying the blockchain, sending transactions, and listening for events.

What are @ethersproject/abstract-provider's main functionalities?

Querying the Blockchain

This feature allows you to query the current block number from the Ethereum blockchain using a JSON-RPC provider.

const { JsonRpcProvider } = require('@ethersproject/providers');
const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

async function getBlockNumber() {
  const blockNumber = await provider.getBlockNumber();
  console.log('Current block number:', blockNumber);
}

getBlockNumber();

Sending Transactions

This feature demonstrates how to send a transaction on the Ethereum network using a wallet connected to a provider.

const { JsonRpcProvider } = require('@ethersproject/providers');
const { Wallet } = require('@ethersproject/wallet');

const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider);

async function sendTransaction() {
  const tx = {
    to: '0xRecipientAddress',
    value: ethers.utils.parseEther('0.01')
  };
  const transactionResponse = await wallet.sendTransaction(tx);
  console.log('Transaction hash:', transactionResponse.hash);
}

sendTransaction();

Listening for Events

This feature shows how to listen for new blocks being mined on the Ethereum blockchain.

const { JsonRpcProvider } = require('@ethersproject/providers');
const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

provider.on('block', (blockNumber) => {
  console.log('New block mined:', blockNumber);
});

Other packages similar to @ethersproject/abstract-provider

Keywords

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc