This server listens for tweets from specified agents, processes the tweets, and interacts with the Solana blockchain by packaging and sending tweet data as transactions. It uses FastAPI for its web framework and integrates with the Solana blockchain via the solders library.
FastAPI-powered Server: Provides RESTful APIs to interact with the server. Tweet-to-Blockchain Integration: Converts agent tweets into Solana transactions and submits them to the blockchain. Memo Program: Uses the pre-deployed Solana Memo program to store the tweet data on the blockchain for testing. Secure Keypair Management: Ensures private wallet keypairs and environment variables are ignored in version control. Setup Instructions
- Prerequisites Ensure the following are installed on your system:
- Python 3.10 or higher
- Pip (Python package manager)
- Solana CLI (for managing Solana wallets)
- Install Solana CLI
- Node.js (if you plan to extend functionality with frontend integrations)
- Clone the Repository Clone the repository to your local machine:
git clone https://github.com/your-repository-name.git
cd your-repository-name
- Create a Virtual Environment Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate # For macOS/Linux
venv\Scripts\activate # For Windows
- Install Dependencies Install the required Python libraries:
pip install -r requirements.txt
- Set Up Your Environment Create a .env file to store your Solana RPC endpoint and other environment variables:
touch .env
Add the following variables to your .env file:
SOLANA_RPC_URL=https://api.devnet.solana.com
SOLANA_SECRET_KEY=your-comma-separated-secret-key
SOLANA_RPC_URL: The Solana RPC URL to connect to the blockchain.
SOLANA_SECRET_KEY: Your wallet's secret key, stored as a comma-separated list (generated by the Solana CLI).
- Add or Generate a Solana Wallet Option 1: Use an Existing Wallet
If you already have a wallet, place your wallet's JSON file (e.g., solana_wallet.json) in the root of your project.
Option 2: Create a New Wallet
Generate a new wallet using the Solana CLI:
solana-keygen new --outfile solana_wallet.json
Add the public key to your wallet for testing:
solana airdrop 5 --keypair solana_wallet.json
- Run the Server Start the FastAPI server:
uvicorn main:app --reload
The server will be available at http://127.0.0.1:8000.
API Endpoints
- Send Tweet to Blockchain
This endpoint sends a tweet to the Solana blockchain using the Memo program. Endpoint: POST /send_tweet Request Body:
{
"agent_handle": "@agent_x",
"tweet": "This is an example tweet!"
}
Response:
{
"status": "success",
"transaction_signature": "5FJ9sKj2FjMd4sG5cqEMX43d7WEsFSYLDnPhxy8P7BV8"
}
Example Request (Using curl):
curl -X POST "http://127.0.0.1:8000/send_tweet" \
-H "Content-Type: application/json" \
-d '{"agent_handle": "@agent_x", "tweet": "This is an example tweet!"}'
Example Response:
{
"status": "success",
"transaction_signature": "5FJ9sKj2FjMd4sG5cqEMX43d7WEsFSYLDnPhxy8P7BV8"
}
- Tweet Submission: The client sends the agent's handle and tweet content to the /send_tweet endpoint.
- Blockchain Interaction: The server creates a transaction with the tweet content and submits it to the Solana blockchain using the Memo program.
- Transaction Response: The server returns the transaction signature, which can be verified on the Solana Explorer.
.
├── main.py # FastAPI server file
├── utils/
│ ├── solana_utils.py # Solana interaction logic (sending transactions)
│ ├── __init__.py # Utility module init
├── solana_wallet.json # (Ignored) Solana wallet file
├── .env # Environment variables (ignored)
├── .gitignore # Git ignore file
├── requirements.txt # Python dependencies
└── README.md # Project README file
- Environment Variables: Sensitive information, such as private keys and RPC URLs, should be stored in .env files. Add .env to .gitignore to ensure it is not committed to version control.
- Wallet Management: Treat your solana_wallet.json file as sensitive. Do not expose it publicly. Use separate wallets for development, testing, and production.
- Public Repositories: If you've accidentally committed a private key, consider the wallet compromised. Generate a new wallet immediately.
- Real-Time Tweet Monitoring: Use the Twitter API to stream tweets and automatically send them to the blockchain.
- Custom Solana Programs: Replace the Memo program with a custom Solana smart contract for processing tweet data.
- Frontend Integration: Build a user-friendly interface to interact with the server.
Contributions are welcome! If you'd like to improve this project, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
If you have any questions or feedback, feel free to reach out!
X: @JJS_OnChain
Email: [email protected]