Skip to content

Rust API built with Axum and ethers-rs to fetch ETH and ERC-20 token balances on Ethereum via Alchemy.

Notifications You must be signed in to change notification settings

RafaelPil/axum-ethers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

axum-ethers

A simple Rust web API built with Axum and ethers-rs to fetch Ethereum ETH and ERC-20 token balances using Alchemy’s JSON-RPC API.

Features

  • Fetch ETH balance for any Ethereum address
  • Fetch ERC-20 token balances via Alchemy API
  • Built with async Rust for high performance and safety

Getting Started

Prerequisites

  • Rust (recommended latest stable)
  • An Alchemy API key with Ethereum Mainnet access

Setup

  1. Clone the repository

    git clone https://github.com/RafaelPil/axum-ethers.git
    cd axum-ethers
  2. Create a .env file in the project root with your Alchemy API key:

    ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY
  3. Build and run the server:

    cargo run
  4. The server will run on http://localhost:3000

Usage

  • Get ETH balance for an address:

    curl http://localhost:3000/eth/balance/address
  • Get ERC-20 token balances for an address:

    curl curl http://localhost:3000/eth/tokens/address

Project Structure

  • main.rs: app entry point, routing setup
  • handlers.rs: request handlers for balances
  • .env: environment variables (not committed to Git)

Notes

  • Make sure .env is included in .gitignore to keep your API keys private.
  • This project uses Alchemy’s API; ensure your API key has the necessary permissions.
  • Extend or customize the token balance parsing to fit your needs.

About

Rust API built with Axum and ethers-rs to fetch ETH and ERC-20 token balances on Ethereum via Alchemy.

Topics

Resources

Stars

Watchers

Forks

Languages