/create-mailbox
POSTCreate a new mailbox for receiving CloudCoin mail.
POST /api/mail/create-mailbox
Description
This endpoint creates a new mailbox that can be used to receive CloudCoin mail. A mailbox is created by depositing a CloudCoin of a specific denomination and serial number. Once created, the mailbox can receive mail sent to its unique address.
Mailbox Creation
When you create a mailbox, a CloudCoin is used to establish the mailbox address. The denomination and serial number uniquely identify your mailbox on the network.
Interactive API Tester
Try it out
Request Body
The request must include a JSON body with the CloudCoin details to create the mailbox.
| Parameter | Type | Required | Description |
|---|---|---|---|
denomination |
integer | Yes | The denomination of the CloudCoin (e.g., 1, 5, 25, 100, 250). |
serial_number |
integer | Yes | The serial number of the CloudCoin used to create the mailbox. |
Example Request
{
"denomination": 1,
"serial_number": 123456
}
Response
Upon successful mailbox creation, the endpoint returns a 200 OK response with details about the newly created mailbox.
Response Properties
status
string
The status of the request (e.g., "success", "error").
mailbox_address
string
The unique address of the newly created mailbox.
denomination
integer
The denomination of the CloudCoin used to create the mailbox.
serial_number
integer
The serial number of the CloudCoin used to create the mailbox.
message
string
A message describing the result of the operation.
Example Response
{
"status": "success",
"mailbox_address": "[email protected]",
"denomination": 1,
"serial_number": 123456,
"message": "Mailbox created successfully"
}
Examples
JavaScript Example
const apiHost = 'http://localhost:8080';
async function createMailbox() {
try {
const response = await fetch(`${apiHost}/api/mail/create-mailbox`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
denomination: 1,
serial_number: 123456
})
});
const data = await response.json();
if (data.status === 'success') {
console.log('Mailbox created successfully!');
console.log('Mailbox address:', data.mailbox_address);
console.log('Denomination:', data.denomination);
console.log('Serial number:', data.serial_number);
} else {
console.error('Failed to create mailbox:', data.message);
}
} catch (error) {
console.error('Error creating mailbox:', error);
}
}
createMailbox();
cURL Example
curl -X POST "http://localhost:8080/api/mail/create-mailbox" \
-H "Content-Type: application/json" \
-d '{
"denomination": 1,
"serial_number": 123456
}'
Go Example
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const apiHost = "http://localhost:8080"
type CreateMailboxRequest struct {
Denomination int `json:"denomination"`
SerialNumber int `json:"serial_number"`
}
type CreateMailboxResponse struct {
Status string `json:"status"`
MailboxAddress string `json:"mailbox_address"`
Denomination int `json:"denomination"`
SerialNumber int `json:"serial_number"`
Message string `json:"message"`
}
func main() {
// Create request payload
requestBody := CreateMailboxRequest{
Denomination: 1,
SerialNumber: 123456,
}
jsonData, _ := json.Marshal(requestBody)
// Make POST request
resp, err := http.Post(
fmt.Sprintf("%s/api/mail/create-mailbox", apiHost),
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
// Read response
body, _ := ioutil.ReadAll(resp.Body)
var result CreateMailboxResponse
json.Unmarshal(body, &result)
if result.Status == "success" {
fmt.Printf("Mailbox created successfully!\n")
fmt.Printf("Mailbox address: %s\n", result.MailboxAddress)
fmt.Printf("Denomination: %d\n", result.Denomination)
fmt.Printf("Serial number: %d\n", result.SerialNumber)
} else {
fmt.Printf("Failed to create mailbox: %s\n", result.Message)
}
}