This project provides a production-grade API to create and manage tokens on the Solana blockchain using the Pump.fun platform. Built with FastAPI, it offers endpoints for creating tokens, buying tokens, and performing both actions together.
- Create custom tokens with metadata uploaded to IPFS.
- Purchase tokens immediately after creation.
- Integrated logging using
loguru
. - Robust error handling with detailed feedback.
- CORS-enabled for cross-origin requests.
- Configurable endpoints with middleware support.
- Python 3.9 or higher
- Solana development environment set up
- Dependencies installed (see below)
-
Clone the Repository:
git clone https://github.com/The-Swarm-Corporation/Swarms-Exchange-API cd Swarms-Exchange-API
-
Install Dependencies:
pip install -r requirements.txt
-
Run the Application:
uvicorn main:app --host 0.0.0.0 --port 8000
-
Access API Documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /create-token
Uploads token metadata to IPFS and creates a new token on the Solana blockchain.
{
"private_key": "<base58-private-key>",
"token_name": "MyToken",
"token_symbol": "MTK",
"description": "This is a test token.",
"twitter": "https://twitter.com/mytoken",
"telegram": "https://t.me/mytoken",
"website": "https://mytoken.com",
"amount": 1000,
"slippage": 10,
"priority_fee": 0.0005,
"pool": "pump",
"rpc_endpoint": "https://api.mainnet-beta.solana.com/"
}
{
"message": "Token created successfully",
"transaction_url": "https://solscan.io/tx/<transaction-id>"
}
POST /buy-token
Allows users to purchase existing tokens.
{
"private_key": "<base58-private-key>",
"mint_address": "<mint-address>",
"amount": 100,
"slippage": 10,
"priority_fee": 0.0005,
"pool": "pump",
"rpc_endpoint": "https://api.mainnet-beta.solana.com/"
}
{
"message": "Token purchased successfully",
"transaction_url": "https://solscan.io/tx/<transaction-id>"
}
POST /create-and-buy
Combines token creation and purchase into a single action.
{
"private_key": "<base58-private-key>",
"token_name": "MyToken",
"token_symbol": "MTK",
"description": "This is a test token.",
"twitter": "https://twitter.com/mytoken",
"telegram": "https://t.me/mytoken",
"website": "https://mytoken.com",
"total_tokens": 1000,
"slippage": 10,
"priority_fee": 0.0005,
"pool": "pump",
"rpc_endpoint": "https://api.mainnet-beta.solana.com/"
}
{
"message": "Token created and purchased successfully",
"create_transaction_url": "https://solscan.io/tx/<create-transaction-id>",
"buy_transaction_url": "https://solscan.io/tx/<buy-transaction-id>"
}
- Ensure your environment supports Python's FastAPI and Solana libraries.
- Configure Solana RPC endpoints if using custom networks.
- All API activities are logged using
loguru
for better debugging and traceability.
Detailed HTTP exceptions and logs are provided for issues related to:
- Metadata upload
- Token creation
- Transaction signing and submission
- Swarm fee transfers
This project is licensed under the MIT License.