SDKs overview

INFURA provides access to the Ethereum network through a robust API, allowing developers to build decentralized applications (dApps) without operating their own full nodes. To simplify interaction with this API, developers commonly use Software Development Kits (SDKs) and client libraries. These tools abstract the underlying JSON-RPC protocol, enabling interaction with Ethereum smart contracts and blockchain data using familiar programming language constructs.

While INFURA itself offers an API, it generally recommends and supports established community SDKs for various languages rather than developing its own proprietary SDKs. The most commonly used JavaScript libraries for interacting with the Ethereum blockchain, and by extension with Infura's API, are Web3.js and Ethers.js. These libraries provide methods for sending transactions, interacting with smart contracts, and querying blockchain data, all routed through an Infura endpoint.

Developers can connect to INFURA's Ethereum API using any library that supports standard Ethereum JSON-RPC calls. This flexibility allows integration into a wide range of applications and development environments, supporting languages such as JavaScript, Python, and Go through various community-maintained libraries.

Official SDKs by language

While INFURA does not maintain its own distinct SDKs, it provides comprehensive documentation and support for integrating with widely adopted Ethereum client libraries. These libraries act as the primary interface for developers to interact with the Ethereum blockchain via an Infura endpoint. The following table highlights the most prominent SDKs and libraries officially supported and recommended by Infura for development:

Language Package Name Description Install Command (npm/pip) Maturity
JavaScript/TypeScript web3.js A collection of libraries that allow you to interact with a local or remote ethereum node using HTTP, IPC or WebSocket. npm install web3 or yarn add web3 Stable, widely used
JavaScript/TypeScript ethers.js A complete and compact library for interacting with the Ethereum Blockchain and its ecosystem. npm install ethers or yarn add ethers Stable, widely used
Python web3.py A Python library for interacting with Ethereum. pip install web3 Stable, actively maintained
Go go-ethereum (client.go) Go bindings for the Ethereum RPC API. Part of the official Go Ethereum client. go get github.com/ethereum/go-ethereum/ethclient Stable, actively maintained

These libraries enable developers to perform actions such as fetching block data, checking account balances, deploying smart contracts, and sending transactions by routing their requests through their INFURA project endpoint (https://mainnet.infura.io/v3/YOUR_PROJECT_ID for Ethereum Mainnet, for example). For detailed usage, refer to the Infura API reference documentation.

Installation

Installation of these libraries typically involves using package managers specific to the programming language. The following steps outline the common installation processes for the primary SDKs:

JavaScript/TypeScript (Web3.js and Ethers.js)

For Node.js projects, use npm or yarn:

# Install Web3.js
npm install web3

# Or using yarn
yarn add web3

# Install Ethers.js
npm install ethers

# Or using yarn
yarn add ethers

For front-end development, these packages can also be included via CDN or bundled using tools like Webpack or Rollup.

Python (web3.py)

For Python projects, use pip:

# Install web3.py
pip install web3

Ensure you are using a Python virtual environment to manage dependencies effectively.

Go (go-ethereum/ethclient)

For Go projects, use the go get command:

# Install the ethclient package
go get github.com/ethereum/go-ethereum/ethclient

This command fetches the necessary Go packages for interacting with Ethereum RPC endpoints.

Quickstart example

This example demonstrates how to fetch the latest block number from the Ethereum Mainnet using Ethers.js and an INFURA endpoint in a Node.js environment. Replace YOUR_INFURA_PROJECT_ID with your actual Infura Project ID.

// Require the ethers.js library
const { ethers } = require("ethers");

// Replace with your actual Infura Project ID
const INFURA_PROJECT_ID = "YOUR_INFURA_PROJECT_ID";

// Define the Infura URL for the Ethereum Mainnet
const INFURA_URL = `https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}`;

// Create a provider instance using Infura's URL
const provider = new ethers.JsonRpcProvider(INFURA_URL);

async function getLatestBlockNumber() {
  try {
    // Fetch the latest block number
    const blockNumber = await provider.getBlockNumber();
    console.log(`The latest Ethereum block number is: ${blockNumber}`);

    // Example: Get network information
    const network = await provider.getNetwork();
    console.log(`Connected to network: ${network.name} (Chain ID: ${network.chainId})`);

  } catch (error) {
    console.error("Error fetching latest block number:", error);
  }
}

// Call the function to execute
getLatestBlockNumber();

To run this example:

  1. Save the code as get-block.js.
  2. Make sure you have Node.js and npm/yarn installed.
  3. Install Ethers.js: npm install ethers
  4. Execute from your terminal: node get-block.js

This will output the current latest block number on the Ethereum Mainnet, demonstrating a basic interaction with the Infura API through Ethers.js. More complex operations, such as interacting with smart contracts or sending transactions, follow similar patterns, requiring wallet integration for signing transactions.

Community libraries

Beyond the primary SDKs, the broader Ethereum ecosystem offers a variety of community-driven libraries and tools that can be used effectively with INFURA. These libraries often specialize in specific use cases or offer alternative approaches to interacting with the blockchain. Developers frequently combine these with Web3.js or Ethers.js for enhanced functionality:

  • Truffle Suite: A development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM). Truffle integrates seamlessly with Infura for deployment and interaction with smart contracts on various networks. Truffle network configuration details how to set an Infura endpoint.
  • Hardhat: A flexible and extensible development environment for compiling, deploying, testing, and debugging Ethereum software. Hardhat can be configured to use Infura as its RPC provider for network interactions. The Hardhat configuration documentation provides setup examples.
  • web3-react: A small, universal library for building DApps with React. It simplifies connecting to various wallet providers and interacting with the Ethereum blockchain, often using Ethers.js or Web3.js internally and routing through Infura. Developers can implement web3-react connectors for Infura.
  • Moralis SDK: While a broader Web3 development platform, Moralis offers SDKs that abstract blockchain interactions, often leveraging providers like Infura in their backend to deliver data. It provides APIs and SDKs for various languages to build dApps with less boilerplate. The Moralis SDK offers methods for querying blockchain data.
  • Alchemy SDK (via Ethers.js/Web3.js): Although Alchemy is an alternative node provider, many developers use Ethers.js or Web3.js with an Alchemy endpoint. The same client-side libraries are compatible with any JSON-RPC provider, including Infura, making the choice of library independent of the node service. Alchemy SDK quickstart provides context for using these libraries with different providers.
  • Brownie: A Python-based development and testing framework for smart contracts targeting the EVM. Brownie can be configured to connect to Infura endpoints for deployment and testing on public networks. Refer to the Brownie network configuration guide.

These community tools enhance the development workflow, offering capabilities from local development and testing to advanced contract interaction and UI integration. Integrating them with INFURA typically involves configuring the RPC endpoint to point to your specific Infura project URL, allowing these tools to leverage Infura's robust node infrastructure.