Skip to content

Commit a60fb53

Browse files
committed
swarms wallet api
1 parent 9c5c1f9 commit a60fb53

File tree

2 files changed

+324
-5
lines changed

2 files changed

+324
-5
lines changed

docs/mkdocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ nav:
294294
- Telemetry API:
295295
- PUT: "swarms_platform/telemetry/index.md"
296296
- Swarms Wallet API:
297-
- Overview: "swarms_platform/wallet/api.md"
297+
- Overview: "swarms/wallet/api.md"
298298
# - Tools API:
299299
# - Overview: "swarms_platform/tools_api.md"
300300
# - Add Tools: "swarms_platform/fetch_tools.md"

docs/swarms/wallet/api.md

+323-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Swarms Wallet API Documentation
1+
# swarms Wallet API Documentation
22

3-
This documentation covers the Swarms Wallet API routes for managing wallets, sending tokens, and checking transactions in the Swarms Platform.
3+
This documentation covers the swarms Wallet API routes for managing wallets, sending tokens, and checking transactions in the swarms Platform.
44

55
## Authentication
66

@@ -34,7 +34,7 @@ POST https://swarms.world/api/solana/generate-wallet
3434
```
3535

3636
### Send Tokens
37-
Sends SWARMS tokens with automatic tax handling.
37+
Sends swarms tokens with automatic tax handling.
3838

3939
```http
4040
POST https://swarms.world/api/solana/send-tokens
@@ -163,7 +163,7 @@ GET https://swarms.world/api/solana/get-metrics
163163
## Transaction Details
164164

165165
- Default SOL fee: 0.009 SOL
166-
- SWARMS token tax: 2% from sender + 2% from sent amount
166+
- swarms token tax: 2% from sender + 2% from sent amount
167167
- All taxes are sent to the DAO treasury
168168
- Token accounts are automatically created for new recipients
169169
- Transactions use 'processed' commitment level
@@ -176,3 +176,322 @@ GET https://swarms.world/api/solana/get-metrics
176176
- Token accounts are automatically created for recipients if they don't exist
177177
- All transactions include automatic tax handling for the DAO treasury
178178
- Compute budget and priority fees are automatically managed for optimal transaction processing
179+
180+
181+
182+
## Examples
183+
184+
Below are code examples in several languages that demonstrate how to use the swarms Wallet API endpoints. In these examples, replace `your_api_key_here` with your actual API key, and update any parameters as needed.
185+
186+
---
187+
188+
## Python (Using `requests`)
189+
190+
First, install the library if you haven’t already:
191+
192+
```bash
193+
pip install requests
194+
```
195+
196+
**Example: Generate Wallet**
197+
198+
```python
199+
import os
200+
import requests
201+
202+
API_KEY = os.getenv("SWARMS_API_KEY")
203+
headers = {
204+
"x-api-key": API_KEY,
205+
"Content-Type": "application/json"
206+
}
207+
208+
url = "https://swarms.world/api/solana/generate-wallet"
209+
response = requests.post(url, headers=headers)
210+
211+
if response.status_code == 200:
212+
data = response.json()
213+
print("Wallet generated:", data)
214+
else:
215+
print("Error:", response.text)
216+
```
217+
218+
**Example: Send Tokens**
219+
220+
```python
221+
import requests
222+
import json
223+
import os
224+
225+
API_KEY = os.getenv("SWARMS_API_KEY")
226+
headers = {
227+
"x-api-key": API_KEY,
228+
"Content-Type": "application/json"
229+
}
230+
231+
url = "https://swarms.world/api/solana/send-tokens"
232+
payload = {
233+
"recipientAddress": "recipient_public_key",
234+
"amount": 100, # Example token amount
235+
# "solanaFee": 0.009 # Optional: use default if not provided
236+
}
237+
238+
response = requests.post(url, headers=headers, data=json.dumps(payload))
239+
if response.status_code == 200:
240+
data = response.json()
241+
print("Tokens sent:", data)
242+
else:
243+
print("Error:", response.text)
244+
```
245+
246+
**Example: Check Receipt**
247+
248+
```python
249+
import requests
250+
import os
251+
252+
API_KEY = os.getenv("SWARMS_API_KEY")
253+
headers = {
254+
"x-api-key": API_KEY
255+
}
256+
257+
amount = 100 # The amount you expect to be received
258+
url = f"https://swarms.world/api/solana/check-receipt?amount={amount}"
259+
260+
response = requests.get(url, headers=headers)
261+
if response.status_code == 200:
262+
data = response.json()
263+
print("Receipt checked:", data)
264+
else:
265+
print("Error:", response.text)
266+
```
267+
268+
**Example: Get Metrics**
269+
270+
```python
271+
import requests
272+
import os
273+
274+
API_KEY = os.getenv("SWARMS_API_KEY")
275+
headers = {
276+
"x-api-key": API_KEY
277+
}
278+
279+
params = {
280+
"page": 1,
281+
"limit": 10,
282+
# Optionally include startDate, endDate, status, type if needed.
283+
}
284+
285+
url = "https://swarms.world/api/solana/get-metrics"
286+
response = requests.get(url, headers=headers, params=params)
287+
if response.status_code == 200:
288+
data = response.json()
289+
print("Metrics:", data)
290+
else:
291+
print("Error:", response.text)
292+
```
293+
294+
---
295+
296+
## Node.js (Using `axios`)
297+
298+
First, install axios:
299+
300+
```bash
301+
npm install axios
302+
```
303+
304+
**Example: Generate Wallet**
305+
306+
```javascript
307+
const axios = require('axios');
308+
309+
const API_KEY = 'your_api_key_here';
310+
const headers = {
311+
'x-api-key': API_KEY,
312+
'Content-Type': 'application/json'
313+
};
314+
315+
axios.post('https://swarms.world/api/solana/generate-wallet', {}, { headers })
316+
.then(response => {
317+
console.log('Wallet generated:', response.data);
318+
})
319+
.catch(error => {
320+
console.error('Error:', error.response ? error.response.data : error.message);
321+
});
322+
```
323+
324+
**Example: Send Tokens**
325+
326+
```javascript
327+
const axios = require('axios');
328+
329+
const API_KEY = 'your_api_key_here';
330+
const headers = {
331+
'x-api-key': API_KEY,
332+
'Content-Type': 'application/json'
333+
};
334+
335+
const payload = {
336+
recipientAddress: 'recipient_public_key',
337+
amount: 100, // token amount
338+
// solanaFee: 0.009 // Optional
339+
};
340+
341+
axios.post('https://swarms.world/api/solana/send-tokens', payload, { headers })
342+
.then(response => {
343+
console.log('Tokens sent:', response.data);
344+
})
345+
.catch(error => {
346+
console.error('Error:', error.response ? error.response.data : error.message);
347+
});
348+
```
349+
350+
**Example: Check Receipt**
351+
352+
```javascript
353+
const axios = require('axios');
354+
355+
const API_KEY = 'your_api_key_here';
356+
const headers = { 'x-api-key': API_KEY };
357+
const amount = 100;
358+
const url = `https://swarms.world/api/solana/check-receipt?amount=${amount}`;
359+
360+
axios.get(url, { headers })
361+
.then(response => {
362+
console.log('Receipt:', response.data);
363+
})
364+
.catch(error => {
365+
console.error('Error:', error.response ? error.response.data : error.message);
366+
});
367+
```
368+
369+
**Example: Get Metrics**
370+
371+
```javascript
372+
const axios = require('axios');
373+
374+
const API_KEY = 'your_api_key_here';
375+
const headers = { 'x-api-key': API_KEY };
376+
377+
const params = {
378+
page: 1,
379+
limit: 10,
380+
// startDate: '2025-01-01', endDate: '2025-01-31', status: 'completed', type: 'send'
381+
};
382+
383+
axios.get('https://swarms.world/api/solana/get-metrics', { headers, params })
384+
.then(response => {
385+
console.log('Metrics:', response.data);
386+
})
387+
.catch(error => {
388+
console.error('Error:', error.response ? error.response.data : error.message);
389+
});
390+
```
391+
392+
---
393+
394+
## cURL (Command Line)
395+
396+
**Example: Generate Wallet**
397+
398+
```bash
399+
curl -X POST https://swarms.world/api/solana/generate-wallet \
400+
-H "x-api-key: your_api_key_here" \
401+
-H "Content-Type: application/json"
402+
```
403+
404+
**Example: Send Tokens**
405+
406+
```bash
407+
curl -X POST https://swarms.world/api/solana/send-tokens \
408+
-H "x-api-key: your_api_key_here" \
409+
-H "Content-Type: application/json" \
410+
-d '{
411+
"recipientAddress": "recipient_public_key",
412+
"amount": 100,
413+
"solanaFee": 0.009
414+
}'
415+
```
416+
417+
**Example: Check Receipt**
418+
419+
```bash
420+
curl -X GET "https://swarms.world/api/solana/check-receipt?amount=100" \
421+
-H "x-api-key: your_api_key_here"
422+
```
423+
424+
**Example: Get Metrics**
425+
426+
```bash
427+
curl -X GET "https://swarms.world/api/solana/get-metrics?page=1&limit=10" \
428+
-H "x-api-key: your_api_key_here"
429+
```
430+
431+
---
432+
433+
## Other Languages
434+
435+
### Ruby (Using `net/http`)
436+
437+
**Example: Generate Wallet**
438+
439+
```ruby
440+
require 'net/http'
441+
require 'uri'
442+
require 'json'
443+
444+
uri = URI.parse("https://swarms.world/api/solana/generate-wallet")
445+
request = Net::HTTP::Post.new(uri)
446+
request["x-api-key"] = "your_api_key_here"
447+
request["Content-Type"] = "application/json"
448+
449+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
450+
http.request(request)
451+
end
452+
453+
puts JSON.parse(response.body)
454+
```
455+
456+
### Java (Using `HttpURLConnection`)
457+
458+
**Example: Generate Wallet**
459+
460+
```java
461+
import java.io.*;
462+
import java.net.*;
463+
import javax.net.ssl.HttpsURLConnection;
464+
465+
public class SwarmsApiExample {
466+
public static void main(String[] args) {
467+
try {
468+
URL url = new URL("https://swarms.world/api/solana/generate-wallet");
469+
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
470+
conn.setRequestMethod("POST");
471+
conn.setRequestProperty("x-api-key", "your_api_key_here");
472+
conn.setRequestProperty("Content-Type", "application/json");
473+
conn.setDoOutput(true);
474+
475+
// If you need to send a request body, write to the output stream:
476+
// try(OutputStream os = conn.getOutputStream()) {
477+
// byte[] input = "{}".getBytes("utf-8");
478+
// os.write(input, 0, input.length);
479+
// }
480+
481+
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
482+
StringBuilder response = new StringBuilder();
483+
String responseLine = null;
484+
while ((responseLine = br.readLine()) != null) {
485+
response.append(responseLine.trim());
486+
}
487+
System.out.println("Response: " + response.toString());
488+
} catch (Exception e) {
489+
e.printStackTrace();
490+
}
491+
}
492+
}
493+
```
494+
495+
---
496+
497+
These examples illustrate how to authenticate using the API key and perform various operations such as generating a wallet, sending tokens, checking receipts, and retrieving metrics. You can adapt these examples to other languages or frameworks as needed. Enjoy integrating with the swarms Wallet API!

0 commit comments

Comments
 (0)