Skip to main content

Backup Tokens

Keep Flexi bots trading on the customer's own tokens once their SOL runs low. The customer sends their token to a backup wallet. When a bot on that token holds less SOL than its threshold, a round tops it up from the backup wallet: right after the round's buy a few tokens move into the round wallet, and the round's sell, which sells everything, turns them into SOL. There is no separate sale and nothing to configure.

The backup wallet belongs to the user and the token, not to one bot. Every Flexi bot of the user on that token, running now or started later, draws from the same wallet.

How much a round takes:

  • Threshold: the smaller of the bot's max swap and the SOL it started with.
  • Top-ups: a round below the threshold takes a few tokens at a time, always a small part of what the round itself bought, so a bot far below its threshold climbs back over several rounds rather than in one large sale.
  • Holder mode: a round that takes a top-up keeps no holder.

Tokens stay in the backup wallet after the bots end. Take them out with POST /flexi/backup/withdraw.


POST /flexi/backup​

Get the user's backup wallet for a token, creating it on the first call. Repeat calls return the same wallet.

Body​

FieldTypeRequiredDescription
sTokenAddressstringyesToken mint.

Response 200​

{
"sTokenAddress": "<mint>",
"sAddress": "<backup wallet>",
"nTokens": 1250.5,
"nSol": 0,
"nTopUps": 3,
"nToppedUpTokens": 410.2,
"nToppedUpSol": 0.0312,
"dLastTopUpAt": "2026-11-26T12:03:10.000Z"
}
FieldDescription
sAddressSend the token here. Send only this token: the wallet holds no SOL, and nothing else sent to it can be recovered through the API.
nTokensTokens in the wallet now, in whole units. null when the balance could not be read; retry.
nSolSOL in the wallet, sent to pay a withdrawal without sPayerWallet. null when it could not be read.
nTopUps, nToppedUpTokens, nToppedUpSolTotals of all top-ups so far. SOL is valued at the price of the buy each top-up rode on.
dLastTopUpAtTime of the last top-up, or null.

Errors​

StatusMeaning
400sTokenAddress is missing or not a valid public key, or is not a token mint.
500Internal server error.

GET /flexi/backup/:tokenAddress​

Read the user's backup wallet for a token without creating one. Responds like POST /flexi/backup.

Errors​

StatusMeaning
400tokenAddress is not a valid public key.
404Backup wallet not found: the user has none for this token.
500Internal server error.

POST /flexi/backup/withdraw​

Send every token in the backup wallet to an address. The backup wallet stays open for the next deposit. Someone has to pay the network fee and, when the destination has none yet, the rent of its token account (about 0.002 SOL in all). Either:

  • one of the user's wallets pays: pass it as sPayerWallet. It needs at least 0.003 SOL; or
  • the backup wallet pays from its own SOL: leave sPayerWallet out and first send at least 0.004 SOL to sAddress. Check nSol with GET /flexi/backup/:tokenAddress. The extra 0.001 SOL keeps the wallet rent-exempt. Once the tokens have landed, a second transaction sends whatever SOL is left, minus its 0.000005 SOL fee, to sDestination as well, and the backup wallet ends with no SOL. If that second transfer fails, the SOL stays in the backup wallet and counts toward the next withdrawal; nSolReturned is then 0.

A bot may be topping up from the wallet at the same moment. Read the balance after a withdrawal rather than assuming it is zero.

Headers​

HeaderRequiredDescription
Idempotency-Keyno8–128 chars of [A-Za-z0-9_-]. A retry with the same key within 24 hours returns the first response (with Idempotent-Replayed: true) instead of withdrawing again. 409 while the first request is still running; 503 if idempotency is unavailable.

Body​

FieldTypeRequiredDescription
sTokenAddressstringyesToken mint of the backup wallet.
sPayerWalletstringnoOne of the user's wallets (see GET /wallets/all). It pays the fee. Wallets imported for Smart Sell cannot pay. Leave it out to pay from SOL in the backup wallet.
sDestinationstringyesWallet to receive the tokens. Must be a regular wallet address, not a program account.

Response 200​

{
"signature": "<transaction signature>",
"sTokenAddress": "<mint>",
"sFrom": "<backup wallet>",
"sDestination": "<destination>",
"nTokens": 1250.5,
"nSolReturned": 0.00249
}

nSolReturned is the SOL sent back to sDestination after a withdrawal the backup wallet paid for itself, and 0 when sPayerWallet paid.

Errors​

StatusMeaning
400Validation failed (missing or invalid address), or the withdrawal was refused: There are no tokens to withdraw., The paying wallet needs at least 0.003 SOL for the fee., Send at least 0.004 SOL to the backup wallet <address> for the fee., Send to a wallet address, not a program account., That is the backup wallet itself., Could not read the balance, try again., The withdrawal did not go through, try again., Could not load paying wallet keypair, or a bad Idempotency-Key.
403sPayerWallet was imported for Smart Sell and only signs there.
404Backup wallet not found, or Paying wallet not found or does not belong to this user.
409A request with this Idempotency-Key is still running.
500Internal server error.

Example​

# 1. Get the backup wallet, then send the token to sAddress.
curl -X POST "$BASE_URL/flexi/backup" \
-H "Authorization: Bearer $ACCESS" \
-H "x-user-id: $USER_ID" \
-H "Content-Type: application/json" \
-d '{ "sTokenAddress": "<mint>" }'

# 2. Later, take what is left. To pay from the backup wallet instead,
# send it 0.004 SOL first and leave out sPayerWallet.
curl -X POST "$BASE_URL/flexi/backup/withdraw" \
-H "Authorization: Bearer $ACCESS" \
-H "x-user-id: $USER_ID" \
-H "Idempotency-Key: backup-withdraw-001" \
-H "Content-Type: application/json" \
-d '{ "sTokenAddress": "<mint>", "sPayerWallet": "<user wallet>", "sDestination": "<destination>" }'