swarms wallet api

pull/762/head
Kye Gomez 2 months ago
parent 9c5c1f9bfa
commit a60fb53279

@ -294,7 +294,7 @@ nav:
- Telemetry API: - Telemetry API:
- PUT: "swarms_platform/telemetry/index.md" - PUT: "swarms_platform/telemetry/index.md"
- Swarms Wallet API: - Swarms Wallet API:
- Overview: "swarms_platform/wallet/api.md" - Overview: "swarms/wallet/api.md"
# - Tools API: # - Tools API:
# - Overview: "swarms_platform/tools_api.md" # - Overview: "swarms_platform/tools_api.md"
# - Add Tools: "swarms_platform/fetch_tools.md" # - Add Tools: "swarms_platform/fetch_tools.md"

@ -1,6 +1,6 @@
# Swarms Wallet API Documentation # swarms Wallet API Documentation
This documentation covers the Swarms Wallet API routes for managing wallets, sending tokens, and checking transactions in the Swarms Platform. This documentation covers the swarms Wallet API routes for managing wallets, sending tokens, and checking transactions in the swarms Platform.
## Authentication ## Authentication
@ -34,7 +34,7 @@ POST https://swarms.world/api/solana/generate-wallet
``` ```
### Send Tokens ### Send Tokens
Sends SWARMS tokens with automatic tax handling. Sends swarms tokens with automatic tax handling.
```http ```http
POST https://swarms.world/api/solana/send-tokens POST https://swarms.world/api/solana/send-tokens
@ -163,7 +163,7 @@ GET https://swarms.world/api/solana/get-metrics
## Transaction Details ## Transaction Details
- Default SOL fee: 0.009 SOL - Default SOL fee: 0.009 SOL
- SWARMS token tax: 2% from sender + 2% from sent amount - swarms token tax: 2% from sender + 2% from sent amount
- All taxes are sent to the DAO treasury - All taxes are sent to the DAO treasury
- Token accounts are automatically created for new recipients - Token accounts are automatically created for new recipients
- Transactions use 'processed' commitment level - Transactions use 'processed' commitment level
@ -176,3 +176,322 @@ GET https://swarms.world/api/solana/get-metrics
- Token accounts are automatically created for recipients if they don't exist - Token accounts are automatically created for recipients if they don't exist
- All transactions include automatic tax handling for the DAO treasury - All transactions include automatic tax handling for the DAO treasury
- Compute budget and priority fees are automatically managed for optimal transaction processing - Compute budget and priority fees are automatically managed for optimal transaction processing
## Examples
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.
---
## Python (Using `requests`)
First, install the library if you havent already:
```bash
pip install requests
```
**Example: Generate Wallet**
```python
import os
import requests
API_KEY = os.getenv("SWARMS_API_KEY")
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
url = "https://swarms.world/api/solana/generate-wallet"
response = requests.post(url, headers=headers)
if response.status_code == 200:
data = response.json()
print("Wallet generated:", data)
else:
print("Error:", response.text)
```
**Example: Send Tokens**
```python
import requests
import json
import os
API_KEY = os.getenv("SWARMS_API_KEY")
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
url = "https://swarms.world/api/solana/send-tokens"
payload = {
"recipientAddress": "recipient_public_key",
"amount": 100, # Example token amount
# "solanaFee": 0.009 # Optional: use default if not provided
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
data = response.json()
print("Tokens sent:", data)
else:
print("Error:", response.text)
```
**Example: Check Receipt**
```python
import requests
import os
API_KEY = os.getenv("SWARMS_API_KEY")
headers = {
"x-api-key": API_KEY
}
amount = 100 # The amount you expect to be received
url = f"https://swarms.world/api/solana/check-receipt?amount={amount}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print("Receipt checked:", data)
else:
print("Error:", response.text)
```
**Example: Get Metrics**
```python
import requests
import os
API_KEY = os.getenv("SWARMS_API_KEY")
headers = {
"x-api-key": API_KEY
}
params = {
"page": 1,
"limit": 10,
# Optionally include startDate, endDate, status, type if needed.
}
url = "https://swarms.world/api/solana/get-metrics"
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print("Metrics:", data)
else:
print("Error:", response.text)
```
---
## Node.js (Using `axios`)
First, install axios:
```bash
npm install axios
```
**Example: Generate Wallet**
```javascript
const axios = require('axios');
const API_KEY = 'your_api_key_here';
const headers = {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
};
axios.post('https://swarms.world/api/solana/generate-wallet', {}, { headers })
.then(response => {
console.log('Wallet generated:', response.data);
})
.catch(error => {
console.error('Error:', error.response ? error.response.data : error.message);
});
```
**Example: Send Tokens**
```javascript
const axios = require('axios');
const API_KEY = 'your_api_key_here';
const headers = {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
};
const payload = {
recipientAddress: 'recipient_public_key',
amount: 100, // token amount
// solanaFee: 0.009 // Optional
};
axios.post('https://swarms.world/api/solana/send-tokens', payload, { headers })
.then(response => {
console.log('Tokens sent:', response.data);
})
.catch(error => {
console.error('Error:', error.response ? error.response.data : error.message);
});
```
**Example: Check Receipt**
```javascript
const axios = require('axios');
const API_KEY = 'your_api_key_here';
const headers = { 'x-api-key': API_KEY };
const amount = 100;
const url = `https://swarms.world/api/solana/check-receipt?amount=${amount}`;
axios.get(url, { headers })
.then(response => {
console.log('Receipt:', response.data);
})
.catch(error => {
console.error('Error:', error.response ? error.response.data : error.message);
});
```
**Example: Get Metrics**
```javascript
const axios = require('axios');
const API_KEY = 'your_api_key_here';
const headers = { 'x-api-key': API_KEY };
const params = {
page: 1,
limit: 10,
// startDate: '2025-01-01', endDate: '2025-01-31', status: 'completed', type: 'send'
};
axios.get('https://swarms.world/api/solana/get-metrics', { headers, params })
.then(response => {
console.log('Metrics:', response.data);
})
.catch(error => {
console.error('Error:', error.response ? error.response.data : error.message);
});
```
---
## cURL (Command Line)
**Example: Generate Wallet**
```bash
curl -X POST https://swarms.world/api/solana/generate-wallet \
-H "x-api-key: your_api_key_here" \
-H "Content-Type: application/json"
```
**Example: Send Tokens**
```bash
curl -X POST https://swarms.world/api/solana/send-tokens \
-H "x-api-key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"recipientAddress": "recipient_public_key",
"amount": 100,
"solanaFee": 0.009
}'
```
**Example: Check Receipt**
```bash
curl -X GET "https://swarms.world/api/solana/check-receipt?amount=100" \
-H "x-api-key: your_api_key_here"
```
**Example: Get Metrics**
```bash
curl -X GET "https://swarms.world/api/solana/get-metrics?page=1&limit=10" \
-H "x-api-key: your_api_key_here"
```
---
## Other Languages
### Ruby (Using `net/http`)
**Example: Generate Wallet**
```ruby
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://swarms.world/api/solana/generate-wallet")
request = Net::HTTP::Post.new(uri)
request["x-api-key"] = "your_api_key_here"
request["Content-Type"] = "application/json"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts JSON.parse(response.body)
```
### Java (Using `HttpURLConnection`)
**Example: Generate Wallet**
```java
import java.io.*;
import java.net.*;
import javax.net.ssl.HttpsURLConnection;
public class SwarmsApiExample {
public static void main(String[] args) {
try {
URL url = new URL("https://swarms.world/api/solana/generate-wallet");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("x-api-key", "your_api_key_here");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
// If you need to send a request body, write to the output stream:
// try(OutputStream os = conn.getOutputStream()) {
// byte[] input = "{}".getBytes("utf-8");
// os.write(input, 0, input.length);
// }
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println("Response: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
---
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!
Loading…
Cancel
Save