eden-network / tx-explain

MIT License
2 stars 2 forks source link

TX Explain

TX Explain is a Python-based project that allows you to simulate and analyze blockchain transactions using the Tenderly API and the Anthropic API. It supports multiple blockchain networks, including Ethereum, Arbitrum, Avalanche, and Optimism.

Features

Prerequisites

Before using the TX Explain, ensure that you have the following:

Setup

  1. Clone the repository:
git clone https://github.com/your-username/tx-explain.git
  1. Change into the project directory:
cd tx-explain
  1. Install the required Python dependencies:
pip install -r requirements.txt
  1. Create a .env file from .env.sample in the project root and add your API keys and configuration settings:
ANTHROPIC_API_KEY=your-anthropic-api-key
TENDERLY_ACCOUNT_SLUG=your-tenderly-account-slug
TENDERLY_PROJECT_SLUG=your-tenderly-project-slug
TENDERLY_ACCESS_KEY=your-tenderly-access-key
...
  1. Authenticate Google Cloud:

    a. Install the Google Cloud SDK by following the instructions for your operating system: Google Cloud SDK Installation Guide

    b. Initialize the Google Cloud SDK by running the following command and following the prompts:

    gcloud init

    c. Authenticate your Google Cloud account by running the following command:

    gcloud auth application-default login

    This command will open a browser window where you can sign in to your Google Cloud account and grant the necessary permissions.

    d. Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your Google Cloud credentials JSON file:

    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials.json

    Replace /path/to/your/credentials.json with the actual path to your Google Cloud credentials JSON file.

  2. (Optional) If you want to use a custom system prompt for the Anthropic API, edit the system_prompt.txt file in the project root with your prompt text and pass in -p system_prompt.txt when you run the script.

Usage

Batch Mode

To run TX Explain in batch mode, use the main.py script with the desired command-line arguments:

python main.py -n <network> -s <start_date> -e <end_date> -d <delay_time> -c <max_concurrent_connections> -f <skip_functions> -p <system_prompt_file>

Example:

python main.py -n ethereum -s 2023-05-01 -e 2023-05-02 -d 1.5 -c 2 -f transfer approve -p system_prompt.txt

The script will first run simulate.py to simulate transactions for the specified network and date range, saving the results to a Google Cloud Storage bucket. Then, it will run explain.py to analyze the simulated transaction data using the Anthropic API, saving the analysis results back to the bucket.

Server Mode

To run TX Explain in server mode, use the webserver.py script:

python webserver.py

Project Structure

The project has the following structure:

tx-explain/
│
├── main.py
│
├── simulate.py
│
├── explain.py
│
├── webserver.py
│
├── system_prompt.txt
│
└── .env

Contributing

Contributions to the TX Explain project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.



This README provides an overview of the TX Explain project, including its features, prerequisites, setup instructions, usage guidelines, project structure, and contributing information. It serves as a comprehensive guide for users to understand and get started with the project.

Feel free to modify and enhance the README based on your specific project requirements and additional details you want to include.