token_address_extractor

Crates.iotoken_address_extractor
lib.rstoken_address_extractor
version1.2.2
created_at2025-03-30 13:47:55.596994+00
updated_at2025-06-06 08:20:06.144595+00
descriptionLibrary for extracting blockchain addresses from text.
homepagehttps://github.com/diloytte/AddrXtractor
repositoryhttps://github.com/diloytte/AddrXtractor
max_upload_size
id1612382
size22,003
Diloytte (diloytte)

documentation

README

Extract Blockchain Addresses

This Rust crate provides functions to extract blockchain addresses from a given text input. Currently, it supports:

  • Ethereum-based addresses (e.g., Ethereum, Binance Smart Chain, etc.)
  • Solana addresses
  • Tron addresses

Installation

To use this crate in your Rust project, add the following dependency to your Cargo.toml file:

[dependencies]
extract-blockchain-address = "1.2.0"

Usage

Below is an example of how to use this crate to extract blockchain addresses from a given text:

use extract_blockchain_address::extract_token_address_from_message_text;

fn main() {
    let text = "This message contains an Ethereum address: 0xAb5801a7D398351b8bE11C439e05C5b3259aec9B";
    
    if let Some(address) = extract_token_address_from_message_text(text) {
        println!("Found address: {}", address);
    } else {
        println!("No valid blockchain address found.");
    }
}

Functions

extract_token_address_from_message_text(text: &str) -> Option<String>

This function scans the given text and extracts the first blockchain address found. It supports Ethereum-based, Solana, and Tron addresses.

Example

let text = "Some Solana address: frhb8l7y9qq41qzxyltc2nw8an1rjfllxrf2x9rwllmo";
let result = extract_token_address_from_message_text(text);
assert_eq!(result, Some("frhb8l7y9qq41qzxyltc2nw8an1rjfllxrf2x9rwllmo".to_string()));

Notes

  • This crate only extracts addresses, not ERC-20/SPL token contract addresses.
  • If multiple addresses are present, it returns the first one found in the text.

License

This project is licensed under the MIT License.

Commit count: 12

cargo fmt