Skip to main content
Change page

JavaScript API libraries

Page last update: February 25, 2026

In order for a web app to interact with the Ethereum blockchain (i.e., read blockchain data and/or send transactions to the network), it must connect to an Ethereum node.

For this purpose, every Ethereum client implements the JSON-RPC specification, so there are a uniform set of methods that applications can rely on.

If you want to use JavaScript to connect with an Ethereum node, it's possible to use vanilla JavaScript but several convenience libraries exist within the ecosystem that make this much easier. With these libraries, developers can write intuitive, one-line methods to initialize JSON-RPC requests (under the hood) that interact with Ethereum.

Please note that since The Merge, two connected pieces of Ethereum software - an execution client and a consensus client - are required to run a node. Please ensure your node includes both an execution and consensus client. If your node is not on your local machine (e.g., your node is running on an AWS instance) update the IP addresses in the tutorial accordingly. For more information please see our page on running a node.

Prerequisites

As well as understanding JavaScript, it might be helpful to understand the Ethereum stack and Ethereum clients.

Why use a library?

These libraries abstract away much of the complexity of interacting directly with an Ethereum node. They also provide utility functions (e.g., converting ETH to Gwei) so as a developer you can spend less time dealing with the intricacies of Ethereum clients and more time focused on the unique functionality of your application.

Library features

Connect to Ethereum nodes

Using providers, these libraries allow you to connect to Ethereum and read its data, whether that's over JSON-RPC, INFURA, Etherscan, Alchemy or MetaMask.

Warning: Web3.js was archived on March 4, 2025. Read the announcement (opens in a new tab). Consider using alternative libraries like ethers.js (opens in a new tab) or viem (opens in a new tab) for new projects.

Ethers example

// A BrowserProvider wraps a standard Web3 provider, which is
// what MetaMask injects as window.ethereum into each page
const provider = new ethers.BrowserProvider(window.ethereum)

// The MetaMask plugin also allows signing transactions to
// send ether and pay to change state within the blockchain.
// For this, we need the account signer...
const signer = provider.getSigner()

Web3js example

Once set up you'll be able to query the blockchain for:

  • block numbers
  • gas estimates
  • smart contract events
  • network id
  • and more...

Wallet functionality

These libraries give you functionality to create wallets, manage keys and sign transactions.

Here's an examples from Ethers

Read the full docs (opens in a new tab)

Once set up you'll be able to:

  • create accounts
  • send transactions
  • sign transactions
  • and more...

Interact with smart contract functions

JavaScript client libraries allow your application to call smart contract functions by reading the Application Binary Interface (ABI) of a compiled contract.

The ABI essentially explains the contract's functions in a JSON format and allows you to use it like a normal JavaScript object.

So the following Solidity contract:

Would result in the following JSON:

This means you can:

  • Send a transaction to the smart contract and execute its method
  • Call to estimate the gas a method execution will take when executed in the EVM
  • Deploy a contract
  • And more...

Utility functions

Utility functions give you handy shortcuts that make building with Ethereum a little easier.

ETH values are in Wei by default. 1 ETH = 1,000,000,000,000,000,000 WEI – this means you're dealing with a lot of numbers! web3.utils.toWei converts ether to Wei for you.

And in ethers it looks like this:

// Get the balance of an account (by address or ENS name)
balance = await provider.getBalance("ethers.eth")
// { BigNumber: "2337132817842795605" }

// Often you will need to format the output for the user
// which prefer to see values in ether (instead of wei)
ethers.utils.formatEther(balance)
// '2.337132817842795605'

Available libraries

Web3.js - Ethereum JavaScript API.

Ethers.js - Complete Ethereum wallet implementation and utilities in JavaScript and TypeScript.

The Graph - A protocol for indexing Ethereum and IPFS data and querying it using GraphQL.

Alchemy SDK - Wrapper around Ethers.js with enhanced apis.

viem - TypeScript Interface for Ethereum.

Codex - Real-time, enriched blockchain data API across dozens of chains.

Drift - TypeScript meta-library with built-in caching, hooks, and test mocks.

Further reading

Know of a community resource that helped you? Edit this page and add it!

Tutorials: JavaScript APIs & WebSockets on Ethereum

  • Using WebSockets – How to use WebSockets with Alchemy to subscribe to Ethereum events and make real-time JSON-RPC requests.

Was this article helpful?