Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@ethersproject/providers
Advanced tools
@ethersproject/providers is a module from the ethers.js library that provides a way to interact with Ethereum nodes. It allows developers to connect to Ethereum networks, query blockchain data, and send transactions.
Connecting to a Provider
This feature allows you to connect to an Ethereum node using a JSON-RPC provider. In this example, we use Infura as the provider.
const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
Querying Blockchain Data
This feature allows you to query blockchain data. In this example, we fetch the current block number from the Ethereum network.
const { ethers } = require('ethers');
const provider = new ethers.providers.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 allows you to send transactions on the Ethereum network. In this example, we create a wallet instance and send a transaction to a recipient address.
const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
async function sendTransaction() {
const tx = {
to: '0xRecipientAddress',
value: ethers.utils.parseEther('0.01')
};
const transaction = await wallet.sendTransaction(tx);
console.log('Transaction hash:', transaction.hash);
}
sendTransaction();
web3.js is a popular library for interacting with the Ethereum blockchain. It provides similar functionalities to @ethersproject/providers, such as connecting to Ethereum nodes, querying blockchain data, and sending transactions. However, web3.js has a larger community and more extensive documentation.
ethjs is a lightweight JavaScript library for interacting with the Ethereum blockchain. It provides basic functionalities similar to @ethersproject/providers, such as sending transactions and querying blockchain data. However, it is less feature-rich and has a smaller community compared to ethers.js.
This sub-module is part of the ethers project.
It contains common Provider classes, utility functions for dealing with providers and re-exports many of the classes and types needed implement a custom Provider.
For more information, see the documentation.
Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.
const {
Provider,
BaseProvider,
JsonRpcProvider,
StaticJsonRpcProvider,
UrlJsonRpcProvider,
FallbackProvider,
AlchemyProvider,
CloudflareProvider,
EtherscanProvider,
InfuraProvider,
NodesmithProvider,
IpcProvider,
Web3Provider,
WebSocketProvider,
JsonRpcSigner,
getDefaultProvider,
getNetwork,
Formatter,
// Types
TransactionReceipt,
TransactionRequest,
TransactionResponse,
Listener,
ExternalProvider,
Block,
BlockTag,
EventType,
Filter,
Log,
JsonRpcFetchFunc,
Network,
Networkish
} = require("@ethersproject/providers");
MIT License
FAQs
Ethereum Providers for ethers.
The npm package @ethersproject/providers receives a total of 492,868 weekly downloads. As such, @ethersproject/providers popularity was classified as popular.
We found that @ethersproject/providers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.