kamiPay LogokamiPay Docs

Withdraw

Send USDt or POL back to your whitelisted address

This endpoint withdraws USDt or POL (the matic token) from your kamiPay wallet to a previously whitelisted address. To withdraw from your refund wallet, see Withdraw from the refund wallet.

Instructions are simple, just add the chain, token, amount, the address from and address to. If the addresses are not previously mapped to your user, the endpoint will fail with status 400.

Request Body

NameTypeDescription
chainstringRequired. Indicates the blockchain network in use. Currently only 'polygon' is supported.
tokenstringRequired. Represents the token to withdraw: 'usdt' or 'matic'.
amountfloatRequired. Specifies the amount to withdraw, expressed as a float.
from_addressstringRequired. Represents the sending wallet's address.
to_addressstringRequired. Represents the receiving wallet's address. Must be previously whitelisted.

The receiving address must be previously whitelisted for your account. Non-whitelisted addresses will result in a 400 error.

Example Request

const url = `${baseURL}/v1/wallet/withdraw`;

const body = {
  "chain": "polygon",
  "token": "usdt",
  "amount": 0.10,
  "from_address": "0x1c0aCxxxxxx488fEdce1ab4",
  "to_address": "0x6Fe712cxxxxxx0E72988e68"
};

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${access_token}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});
import requests
import json

url = f"{base_url}/v1/withdraw"

body = {
  "chain": "polygon",
  "token": "usdt",
  "amount": 0.10,
  "from_address": "0x1c0aCxxxxxx488fEdce1ab4",
  "to_address": "0x6Fe712cxxxxxx0E72988e68"
}

headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json',
}

response = requests.post(url, json=body, headers=headers)
package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "net/http"
)

func main() {
  url := fmt.Sprintf("%s/v1/wallet/withdraw", baseURL)
  
  // Create request body
  requestBody, _ := json.Marshal(map[string]interface{}{
    "chain": "polygon",
    "token": "usdt",
    "amount": 0.10,
    "from_address": "0x1c0aCxxxxxx488fEdce1ab4",
    "to_address": "0x6Fe712cxxxxxx0E72988e68",
  })
  
  // Create request
  req, _ := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
  req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", access_token))
  req.Header.Add("Content-Type", "application/json")
  
  // Make the request
  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    fmt.Println("Error making request:", err)
    return
  }
  defer resp.Body.Close()
}

Response

"status": "broadcasted" means that kamiPay sent the transfer to Polygon. It does not mean that the transfer is mined.

A USDt withdrawal. transactionHash and transaction_hash have the same value, the hash of the transfer:

{
  "status": "ok",
  "data": {
    "status": "broadcasted",
    "transactionHash": "0x0c5fabf2a7c76c809b345b6e1d3f8a2c4e6b9d0f2a1c3e5b7d2d414b40503361",
    "transaction_hash": "0x0c5fabf2a7c76c809b345b6e1d3f8a2c4e6b9d0f2a1c3e5b7d2d414b40503361"
  }
}

A POL withdrawal (token: "matic"). transactionHash is the hash of the transfer. to is your to_address in lowercase, and matic amount is your amount:

{
  "status": "ok",
  "data": {
    "status": "broadcasted",
    "transactionHash": "0x7d1e4a9c2b5f8e3d6a0c9b2e5f8a1d4c7b0e3f6a9d2c5b8e1f4a7d0c3b6e9f2a",
    "to": "0x6fe712c4a9d3b8e1f05c27a94d6b3e8f10e72988",
    "matic amount": 0.1
  }
}
{
  "detail": "detailed error will be provided here"
}

With an invalid or expired token:

{
  "detail": "Could not validate credentials"
}
{
  "detail": "an unexpected error occurred"
}

Withdrawal transactions are processed on the blockchain and may take some time to complete depending on network conditions.

Always double-check the receiving address before initiating a withdrawal, as blockchain transactions cannot be reversed once confirmed.

Withdraw from the refund wallet

To withdraw USDt from your refund wallet, send POST /v1/wallet/withdraw with the address of the refund wallet in from_address. These rules apply:

  • Access: credentials with the pay-in scope or the pay-out scope, and a user with a management role (owner, super user or super admin). Other roles get 403.
  • Only USDt: send token: "usdt". kamiPay keeps the POL of the wallet for the gas.
  • Up to the available USDt: amount is more than 0, and not more than the available_usdt of Get Refund Wallet. The USDt of the refunds in progress (reserved_usdt) and the USDt that the wallet owes for a MED (med_owed_usdt) cannot leave.
  • To a registered wallet of your account: to_address is a wallet that kamiPay registered for your account, such as the wallet of a checkout (Wallets). The whitelist of the withdrawal above does not apply.
  • A wallet that other merchants share: the API returns 409. Contact support: kamiPay does the withdrawal.
  • A refund request during a withdrawal gets 503 "refunds are not available now; retry later". Send that refund request again after some seconds.

The response comes when the transfer is mined, or after about 50 seconds. Set the timeout of your HTTP client above 50 seconds. A 200 means that kamiPay sent the transfer: to confirm it, read the wallet with Get Refund Wallet, or find the hash on Polygon. If your client stops before the response, read the wallet before you send the withdrawal again. A second request sends a second transfer.

Example Request

const url = `${baseURL}/v1/wallet/withdraw`;

const body = {
  chain: "polygon",
  token: "usdt",
  amount: 7,
  from_address: "0x4b1e9c7a2f3d58e6a0c4b7d9e2f1a3c5b8d0e6f2", // the refund wallet
  to_address: "0x9c2d7e4f1a6b3c8d5e0f2a7b4c9d6e1f3a8b5c2d", // a wallet of your checkouts
};

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${access_token}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});
import requests

url = f"{base_url}/v1/wallet/withdraw"

body = {
  "chain": "polygon",
  "token": "usdt",
  "amount": 7,
  "from_address": "0x4b1e9c7a2f3d58e6a0c4b7d9e2f1a3c5b8d0e6f2",  # the refund wallet
  "to_address": "0x9c2d7e4f1a6b3c8d5e0f2a7b4c9d6e1f3a8b5c2d",  # a wallet of your checkouts
}

headers = {
  "Authorization": f"Bearer {access_token}",
  "Content-Type": "application/json",
}

response = requests.post(url, json=body, headers=headers)
package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "net/http"
)

func main() {
  url := fmt.Sprintf("%s/v1/wallet/withdraw", baseURL)

  requestBody, _ := json.Marshal(map[string]interface{}{
    "chain":        "polygon",
    "token":        "usdt",
    "amount":       7,
    "from_address": "0x4b1e9c7a2f3d58e6a0c4b7d9e2f1a3c5b8d0e6f2", // the refund wallet
    "to_address":   "0x9c2d7e4f1a6b3c8d5e0f2a7b4c9d6e1f3a8b5c2d", // a wallet of your checkouts
  })

  req, _ := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
  req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", access_token))
  req.Header.Add("Content-Type", "application/json")

  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    fmt.Println("Error making request:", err)
    return
  }
  defer resp.Body.Close()
}

Response

The same response as a USDt withdrawal. Only the time is different: this response comes when the transfer is mined, or after about 50 seconds.

{
  "status": "ok",
  "data": {
    "status": "broadcasted",
    "transactionHash": "0x3e8a1f5c7b2d9e4a6c0f8b3d5e7a9c1f2b4d6e8a0c3f5b7d9e1a2c4f6b8d0e3a",
    "transaction_hash": "0x3e8a1f5c7b2d9e4a6c0f8b3d5e7a9c1f2b4d6e8a0c3f5b7d9e1a2c4f6b8d0e3a"
  }
}

An amount of 0 or less:

{
  "detail": "Wrong amount:0.0"
}

A token that is not "usdt":

{
  "detail": "Incorrect token: only usdt leaves a refund wallet"
}

A to_address that is not a registered wallet of your account:

{
  "detail": "Incorrect to_address: 0x1234567890abcdef1234567890abcdef12345678"
}

Your user does not have a management role:

{
  "detail": "User role not authorized for this endpoint"
}

An amount that is more than the available USDt. The wallet holds 10 USDt and owes 3 USDt for a MED:

{
  "detail": "insufficient USDt in the refund wallet: available=7.000000 required=7.000001"
}

Your account has more than one refund wallet. Contact support:

{
  "detail": "the merchant has more than one refund wallet: contact support"
}

Other merchants share the wallet. Contact support:

{
  "detail": "the refund wallet is shared with other merchants: contact support"
}

kamiPay disabled the refund wallet. Contact support:

{
  "detail": "refund wallet missing or disabled"
}

The transfer failed, and the response cannot show if USDt left the wallet. Read the wallet with Get Refund Wallet before you send the withdrawal again:

{
  "detail": "An unexpected error occurred."
}

A different withdrawal or a refund uses the wallet now. Send the request again after some seconds:

{
  "detail": "the refund wallet is busy; retry later"
}

kamiPay cannot read the balances on Polygon now. No USDt left the wallet. Send the request again later:

{
  "detail": "could not read the refund wallet balances on-chain; retry later"
}

On this page