|
1 | 1 |
|
2 |
| -# Swarms-Example-1-Click-Template |
| 2 | +# Swarms Exchange API |
3 | 3 |
|
4 | 4 | [](https://discord.gg/agora-999382051935506503) [](https://www.youtube.com/@kyegomez3242) [](https://www.linkedin.com/in/kye-g-38759a207/) [](https://x.com/kyegomezb)
|
5 | 5 |
|
6 | 6 |
|
7 | 7 | [](https://github.com/The-Swarm-Corporation/Legal-Swarm-Template)
|
8 | 8 | [](https://github.com/kyegomez/swarms)
|
9 | 9 |
|
| 10 | +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. |
| 11 | + |
| 12 | +## Features |
| 13 | +- Create custom tokens with metadata uploaded to IPFS. |
| 14 | +- Purchase tokens immediately after creation. |
| 15 | +- Integrated logging using `loguru`. |
| 16 | +- Robust error handling with detailed feedback. |
| 17 | +- CORS-enabled for cross-origin requests. |
| 18 | +- Configurable endpoints with middleware support. |
| 19 | + |
| 20 | +## Requirements |
| 21 | + |
| 22 | +- Python 3.9 or higher |
| 23 | +- Solana development environment set up |
| 24 | +- Dependencies installed (see below) |
| 25 | + |
| 26 | +## Installation |
| 27 | + |
| 28 | +1. **Clone the Repository**: |
| 29 | + ```bash |
| 30 | + git clone <repository-url> |
| 31 | + cd <repository-folder> |
| 32 | + ``` |
| 33 | + |
| 34 | +2. **Install Dependencies**: |
| 35 | + ```bash |
| 36 | + pip install -r requirements.txt |
| 37 | + ``` |
| 38 | + |
| 39 | +3. **Run the Application**: |
| 40 | + ```bash |
| 41 | + uvicorn main:app --host 0.0.0.0 --port 8000 |
| 42 | + ``` |
| 43 | + |
| 44 | +4. **Access API Documentation**: |
| 45 | + - Swagger UI: [http://localhost:8000/docs](http://localhost:8000/docs) |
| 46 | + - ReDoc: [http://localhost:8000/redoc](http://localhost:8000/redoc) |
| 47 | + |
| 48 | +## Endpoints |
| 49 | + |
| 50 | +### 1. Create Token |
| 51 | +**POST** `/create-token` |
| 52 | + |
| 53 | +Uploads token metadata to IPFS and creates a new token on the Solana blockchain. |
| 54 | + |
| 55 | +#### Request Body |
| 56 | +```json |
| 57 | +{ |
| 58 | + "private_key": "<base58-private-key>", |
| 59 | + "token_name": "MyToken", |
| 60 | + "token_symbol": "MTK", |
| 61 | + "description": "This is a test token.", |
| 62 | + "twitter": "https://twitter.com/mytoken", |
| 63 | + "telegram": "https://t.me/mytoken", |
| 64 | + "website": "https://mytoken.com", |
| 65 | + "amount": 1000, |
| 66 | + "slippage": 10, |
| 67 | + "priority_fee": 0.0005, |
| 68 | + "pool": "pump", |
| 69 | + "rpc_endpoint": "https://api.mainnet-beta.solana.com/" |
| 70 | +} |
| 71 | +``` |
10 | 72 |
|
11 |
| - |
12 |
| -## 🚀 Quick Start |
13 |
| - |
14 |
| -```bash |
15 |
| -# Clone the repository |
16 |
| -git clone https://github.com/The-Swarm-Corporation/Swarms-Example-1-Click-Template.git |
17 |
| - |
18 |
| -# Install requirements |
19 |
| -pip3 install -r requirements.txt |
20 |
| - |
21 |
| -# Set your task in the .env file or pass it in the yaml file on the bottom `task:` |
22 |
| -export WORKSPACE_DIR="agent_workspace" |
23 |
| -export GROQ_API_KEY="" |
24 |
| - |
25 |
| -# Run the swarm |
26 |
| -python3 main.py |
| 73 | +#### Response |
| 74 | +```json |
| 75 | +{ |
| 76 | + "message": "Token created successfully", |
| 77 | + "transaction_url": "https://solscan.io/tx/<transaction-id>" |
| 78 | +} |
27 | 79 | ```
|
28 | 80 |
|
| 81 | +--- |
29 | 82 |
|
30 |
| -## 🛠 Built With |
| 83 | +### 2. Buy Token |
| 84 | +**POST** `/buy-token` |
| 85 | + |
| 86 | +Allows users to purchase existing tokens. |
| 87 | + |
| 88 | +#### Request Body |
| 89 | +```json |
| 90 | +{ |
| 91 | + "private_key": "<base58-private-key>", |
| 92 | + "mint_address": "<mint-address>", |
| 93 | + "amount": 100, |
| 94 | + "slippage": 10, |
| 95 | + "priority_fee": 0.0005, |
| 96 | + "pool": "pump", |
| 97 | + "rpc_endpoint": "https://api.mainnet-beta.solana.com/" |
| 98 | +} |
| 99 | +``` |
31 | 100 |
|
32 |
| -- [Swarms Framework](https://github.com/kyegomez/swarms) |
33 |
| -- Python 3.10+ |
34 |
| -- GROQ API Key or you can change it to use any model from [Swarm Models](https://github.com/The-Swarm-Corporation/swarm-models) |
| 101 | +#### Response |
| 102 | +```json |
| 103 | +{ |
| 104 | + "message": "Token purchased successfully", |
| 105 | + "transaction_url": "https://solscan.io/tx/<transaction-id>" |
| 106 | +} |
| 107 | +``` |
35 | 108 |
|
36 |
| -## 📬 Contact |
| 109 | +--- |
37 | 110 |
|
38 |
| -Questions? Reach out: |
39 |
| -- Twitter: [@kyegomez](https://twitter.com/kyegomez) |
40 |
| -- Email: kye@swarms.world |
| 111 | +### 3. Create and Buy Tokens |
| 112 | +**POST** `/create-and-buy` |
| 113 | + |
| 114 | +Combines token creation and purchase into a single action. |
| 115 | + |
| 116 | +#### Request Body |
| 117 | +```json |
| 118 | +{ |
| 119 | + "private_key": "<base58-private-key>", |
| 120 | + "token_name": "MyToken", |
| 121 | + "token_symbol": "MTK", |
| 122 | + "description": "This is a test token.", |
| 123 | + "twitter": "https://twitter.com/mytoken", |
| 124 | + "telegram": "https://t.me/mytoken", |
| 125 | + "website": "https://mytoken.com", |
| 126 | + "total_tokens": 1000, |
| 127 | + "slippage": 10, |
| 128 | + "priority_fee": 0.0005, |
| 129 | + "pool": "pump", |
| 130 | + "rpc_endpoint": "https://api.mainnet-beta.solana.com/" |
| 131 | +} |
| 132 | +``` |
41 | 133 |
|
42 |
| ---- |
| 134 | +#### Response |
| 135 | +```json |
| 136 | +{ |
| 137 | + "message": "Token created and purchased successfully", |
| 138 | + "create_transaction_url": "https://solscan.io/tx/<create-transaction-id>", |
| 139 | + "buy_transaction_url": "https://solscan.io/tx/<buy-transaction-id>" |
| 140 | +} |
| 141 | +``` |
43 | 142 |
|
44 |
| -## Want Real-Time Assistance? |
| 143 | +## Environment Variables |
| 144 | +- Ensure your environment supports Python's FastAPI and Solana libraries. |
| 145 | +- Configure Solana RPC endpoints if using custom networks. |
45 | 146 |
|
46 |
| -[Book a call with here for real-time assistance:](https://cal.com/swarms/swarms-onboarding-session) |
| 147 | +## Logging |
| 148 | +- All API activities are logged using `loguru` for better debugging and traceability. |
47 | 149 |
|
48 |
| ---- |
| 150 | +## Error Handling |
| 151 | +Detailed HTTP exceptions and logs are provided for issues related to: |
| 152 | +- Metadata upload |
| 153 | +- Token creation |
| 154 | +- Transaction signing and submission |
| 155 | +- Swarm fee transfers |
49 | 156 |
|
50 |
| -⭐ Star us on GitHub if this project helped you! |
| 157 | +## License |
| 158 | +This project is licensed under the MIT License. |
51 | 159 |
|
52 |
| -Built with ♥ using [Swarms Framework](https://github.com/kyegomez/swarms) |
|
0 commit comments