/exchange/address
POST ASYNCGenerates a one-time cryptocurrency deposit address for a sale.
POST /api/v1/exchange/address
Alias: /generate-sale-payment-address
Description
Before a buyer can purchase a listing, the seller must generate a unique, one-time deposit address for the specified cryptocurrency. The buyer sends their payment to this address. This endpoint is asynchronous and returns a task ID.
Request Body
Parameter | Type | Required | Description |
---|---|---|---|
cointype | integer | Yes | The cryptocurrency for the address (1 for BTC, 2 for XMR). |
price | number | Yes | The price of the sale. |
name | string | Yes | The name of the seller's wallet. |
Response
The final result, available after polling the task, contains the generated address and a unique receipt ID required for the buyer to complete the purchase.
Response Properties (in completed task `data`)
receipt_idstring
A unique receipt ID for the deposit address.
addressstring
The generated one-time deposit address.
Examples
JavaScript Example
const apiHost = 'http://localhost:8006';
// Generic function to poll any task
async function pollTask(taskId) {
const taskResponse = await fetch(`${apiHost}/api/v1/tasks/${taskId}`);
const taskData = await taskResponse.json();
const task = taskData.payload;
console.log(`Task ${taskId} progress: ${task.progress}% - ${task.message}`);
if (task.status === 'completed') {
console.log(`Task finished successfully!`, task.data);
return true; // Stop polling
} else if (task.status === 'error') {
console.error(`Task failed:`, task.message);
return true; // Stop polling
}
return false; // Continue polling
}
async function generateAddress(data) {
const response = await fetch(`${apiHost}/api/v1/exchange/address`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const taskInfo = await response.json();
const taskId = taskInfo.payload.id;
console.log(`GenAddress task created with ID: ${taskId}`);
const pollInterval = setInterval(async () => {
const isDone = await pollTask(taskId);
if (isDone) clearInterval(pollInterval);
}, 2000);
}
generateAddress({ cointype: 1, price: 0.001, name: 'Default' });
cURL Example
# Step 1: Initiate the generate address task
TASK_ID=$(curl -s -X POST "http://localhost:8006/api/v1/exchange/address" \
-H "Content-Type: application/json" \
-d '{"cointype":1, "price":0.001, "name":"Default"}' | jq -r '.payload.id')
echo "Generate address task started with ID: $TASK_ID"
# Step 2: Poll the task endpoint until finished
while true; do
RESPONSE=$(curl -s "http://localhost:8006/api/v1/tasks/$TASK_ID")
STATUS=$(echo $RESPONSE | jq -r '.payload.status')
echo "Polling task.. Status: $STATUS"
if [[ "$STATUS" == "completed" ]] || [[ "$STATUS" == "error" ]]; then
echo "Final Response:"
echo $RESPONSE | jq
break
fi
sleep 2
done
Go Example
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
const apiHost = "http://localhost:8006/api/v1"
type TaskResponse struct {
Payload struct {
ID string `json:"id"`
Status string `json:"status"`
Message string `json:"message"`
Data interface{} `json:"data"`
} `json:"payload"`
}
func pollTask(taskId string) {
for {
resp, err := http.Get(fmt.Sprintf("%s/tasks/%s", apiHost, taskId))
if err != nil { log.Printf("Error polling task: %v\n", err); return }
defer resp.Body.Close()
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
fmt.Printf("Polling... Status: %s, Message: %s\n", taskResp.Payload.Status, taskResp.Payload.Message)
if taskResp.Payload.Status == "completed" {
fmt.Printf("Task completed. Data: %+v\n", taskResp.Payload.Data)
return
} else if taskResp.Payload.Status == "error" {
fmt.Printf("Task failed: %s\n", taskResp.Payload.Message)
return
}
time.Sleep(2 * time.Second)
}
}
func generateAddress(data map[string]interface{}) {
payload, _ := json.Marshal(data)
resp, err := http.Post(fmt.Sprintf("%s/exchange/address", apiHost), "application/json", bytes.NewBuffer(payload))
if err != nil {
log.Fatalf("Failed to start generate address task: %v", err)
}
defer resp.Body.Close()
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
fmt.Printf("Generate address task created with ID: %s\n", taskResp.Payload.ID)
pollTask(taskResp.Payload.ID)
}
func main() {
addressData := map[string]interface{}{
"cointype": 1,
"price": 0.001,
"name": "Default",
}
generateAddress(addressData)
}