Loading Ethereum Transactions with LangChain EtherscanLoader
Posted: Nov 25, 2024.
The LangChain EtherscanLoader provides an interface to load transaction data and account information from the Ethereum blockchain through the Etherscan API. This guide shows you how to use it effectively.
What is EtherscanLoader?
EtherscanLoader is a document loader class that allows you to fetch various types of Ethereum blockchain data including:
- Normal transactions
- Internal transactions
- ERC20 token transfers
- ERC721 (NFT) transfers
- ERC1155 token transfers
- ETH balances
The loader uses the Etherscan API to interact with the Ethereum mainnet and returns the data as LangChain Document objects.
Reference
Here are the key methods provided by EtherscanLoader:
Method | Description |
---|---|
getNormTx() | Get normal transactions for an address |
getInternalTx() | Get internal transactions for an address |
getERC20Tx() | Get ERC20 token transfers for an address |
getERC721Tx() | Get ERC721 (NFT) transfers for an address |
getERC1155Tx() | Get ERC1155 token transfers for an address |
getEthBalance() | Get ETH balance for an address |
load() | Load transactions into Document objects |
lazy_load() | Lazily load transactions as an iterator |
How to Use EtherscanLoader
First, you'll need an Etherscan API key. You can set it as an environment variable:
Basic Usage
The simplest way to use the loader is to fetch normal transactions for an address:
Customizing the Query
You can customize various parameters when creating the loader:
Loading Different Transaction Types
You can specify which type of transactions to load using the filter parameter:
Lazy Loading
For large datasets, you can use lazy loading to iterate through the documents:
Async Loading
The loader also supports async operations:
Remember that the Etherscan API has rate limits, especially for free API keys (5 calls per second). Plan your queries accordingly and implement appropriate rate limiting if needed.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.