Agent API endpoints
Mystery links
Make, claim, open and take back mystery links.
For code that signs with its own wallet (Agent API): the endpoints that make, claim, open and take back mystery links. A mystery link is one pool of tokenized stocks and tokens behind one link, split into prizes of different sizes. Every wallet that claims gets one box and its prize is drawn as it opens. Mystery links live on Base. The fee is 2.5% on top plus a draw fee, both named in summary.fee. Every path here is under https://www.giftedstock.com/api/agent/v1 and every write answers with a plan, as described in Requests, plans and errors. For what a mystery link is to the people who claim one, see Create a mystery link.
Read a mystery link
GET /mystery/{poolId}
GET https://www.giftedstock.com/api/agent/v1/mystery/12
GET https://www.giftedstock.com/api/agent/v1/mystery/12?claimer=0xYou| Field | What it is |
|---|---|
poolId, creator, creatorName | The link's number, the wallet that made it and its name when it has one. |
state | open, not_open_yet, closed (its end date passed), all_claimed, taken_back or not_claimable_here (a gate this site does not serve). |
opensAt, closesAt, openUntil | When claims open ("at once") and close, in ISO 8601, and the last moment a claimed box can be opened: 30 days after the end date. |
boxes, boxesLeft, claimed, opened, drawn | Boxes on the link, those nobody has claimed yet and how many were claimed, opened and drawn. |
prizesUsd | What all the prizes add up to, at the prices the link was made at. The prizes themselves and their odds are never shown, as on the claim page: they stay a surprise. |
items, itemsUsd | What the whole pool holds: each token, its amount and its dollars now. |
who, words, note, design | Who may claim (anyone, verified or list) and in words, the maker's note and the box design word. |
createdAt, linkKeyAddress, contract | When it was made, the address of its link key now and the mystery link contract. |
claimer | With ?claimer=: { wallet, claimed, box, state, opened, drawn, prize }. prize is { usd, contents } once the box is drawn, else null. |
A link made seconds ago answers too: its facts are read from the chain.
Make a mystery link
POST /tx/mystery
POST https://www.giftedstock.com/api/agent/v1/tx/mystery
{
"wallet": "0xYou",
"skill": "1.7.0",
"items": [{ "ticker": "NVDAc", "usd": 20 }, { "ticker": "TSLAc", "usd": 5 }],
"prizes": "ladder",
"link": { "boxes": 16, "who": "anyone", "linkKeyAddress": "0xFreshKeyAddress", "closesAt": "2026-12-31T23:59:00Z" },
"payWith": "USDC",
"note": "good luck"
}| Field | Required | Rule |
|---|---|---|
items | yes | What the whole pool holds, shared by every box: 1 to 20 tokens, each once, as { ticker, usd }: a ticker or address (token is taken too) and its dollars, at most 2 places. Tokenized stocks and tokens the mystery link contract takes; the smallest prize must still hold each token's minimum. |
prizes | yes | How the pool splits: "ladder" (a few big prizes and more smaller ones), "jackpot" (one box gets half the pool, the rest share the other half) or your own list of up to 16 prizes, [{ "usd": 10, "count": 1 }, { "usd": 1, "count": 15 }]. A list must add up to the items' dollars and its counts to link.boxes. |
payWith | yes | "USDC" or "ETH". The router buys each token as the link is made and sends back what it does not spend. |
link | yes | Who claims, when and the link key (below). |
note | no | Up to 140 characters, shown on the claim page. |
design | no | A design word (0x and 64 hex) or { box, ribbon, title, titleColour, stickers }, as a gift's: colours as "#9ccc00", a title up to 16 characters, ribbon null for none, stickers { left, right, top }, each null or one of frog, cat, dog, bull, bear, rocket, diamond, moon, bankr. |
| link field | Required | Rule |
|---|---|---|
boxes | yes | 1 to 100,000, one per wallet. |
who | yes | "anyone" with the link, "verified" (wallets verified on https://www.giftedstock.com/verify) or "list". |
list | with who list | 1 to 100,000 wallet addresses, each checksummed or all lowercase. |
opensAt | no | Unix seconds or ISO 8601. Left out, claims open at once. |
closesAt | no | Unix seconds or ISO 8601. Left out, claims close after 7 days. Every mystery link ends: null or 0 is refused. |
linkKeyAddress | yes | The address of a fresh key you made for this link (below). |
Step 1: Make a link key
Make a fresh key where you run (viem: generatePrivateKey()) and send only its address. Never your wallet's own key, never one used before (by a gift link or a mystery link), never funded: its private key goes into the share URL. A key used before is refused with link_key_used.
Step 2: Check the summary
summary.prizes lists each prize with its count and odds, summary.pool what the pool holds, summary.fee the fee and the draw fee (fee.drawFee), summary.total all of it and summary.pay the most the plan takes.
Step 3: Send the steps
An exact USDC approval when one is needed, then the router's buy. It lasts 20 minutes. In the last receipt, the router's Bought log (topic0 0xda3658575501f28198f60bb28b30f0db3cd49f22a0cd16ce8925f17c1e67a6e6) holds the poolId as topics[1]: summary.link.poolId says the same.
Step 4: Share the URL
https://www.giftedstock.com/gift?pool=<poolId>#k=<link key's private key> (summary.link.shareUrl). Whoever holds it and passes the link's gate can claim one box while boxes are left: give it only to your human or where they say.
Claim from a mystery link
POST /tx/mystery/claim
Two calls. From a share URL, the poolId is ?pool= and the link key is the private key after #k=. The link key stays where you run: it never goes to the API.
POST https://www.giftedstock.com/api/agent/v1/tx/mystery/claim
{ "wallet": "0xYou", "skill": "1.7.0", "poolId": 12 }Step 1: Ask what to sign
Send { wallet, skill, poolId }. The answer (action mystery_claim_sign) has no steps: sign.typedData is an EIP-712 Claim naming your wallet. A wallet the link refuses (not verified, not on the list, claimed before) is told now.
Step 2: Check and sign
primaryType is Claim, domain.chainId is 8453, domain.verifyingContract is the mystery link contract, message.claimer is your wallet and message.poolId is the link's. Sign it with the link key, not your wallet (viem: privateKeyToAccount(linkKey).signTypedData(typedData)).
Step 3: Get the claim
Send { wallet, skill, poolId, signature } and send the one step from your wallet. It claims the box and opens it (summary.opens). When Base's clock is behind drand's it only claims: open the box a few seconds later (below). On a verified-only link the plan lasts ten minutes.
Step 4: Find the box
Its id is topics[2] of the Claimed log (0xc09f7b3c1c5b70bf6d30e485a4525d625d4723aed5d319376825446ef135c7ca). Its prize is drawn within seconds (below).
Open and the draw
POST /tx/mystery/open
POST https://www.giftedstock.com/api/agent/v1/tx/mystery/open
{ "wallet": "0xYou", "skill": "1.7.0", "ids": ["57"] }ids: 1 to 50 boxes this wallet claimed and has not opened. A claim already opens its box, so this is for a box claimed without it. A claimed box can be opened until 30 days after its link's end date, unless the link was taken back.
- Each open takes a drand round published a few seconds after it, so nobody can know the prize when the box is opened.
- Our drawer checks drand's signature for that round onchain, draws the prize from the ones left and sends it to the wallet that holds the box, paid by the draw fee. There is nothing more to send.
- Read the prize with
GET https://www.giftedstock.com/api/agent/v1/mystery/<poolId>?claimer=0xYou. A mystery box stays in the wallet that claimed it and can't be sent on. - How the draw works and how to replay it: Odds and randomness.
Take back what is left
POST /tx/mystery/take-back
POST https://www.giftedstock.com/api/agent/v1/tx/mystery/take-back
{ "wallet": "0xYou", "skill": "1.7.0", "poolId": 12 }- Only the link's maker, from its end date or once every box is claimed.
- It sends back all but the biggest prizes left, one for each claimed box not drawn yet, so whatever those boxes draw is still there. summary.back is what comes back now and summary.staysUsd what stays. Call it again later for what came free since; once no box can draw any more it sends the rest and the link is done (summary.closes).
- A box still sealed 30 days after the end date can no longer be opened: its prize comes free too.
- Tokenized stocks and tokens come back to your wallet, not the USDC or ETH you paid with. The fees are not returned.
Refusals
| Code | Status | From | Meaning |
|---|---|---|---|
| not_live | 404 | every mystery route | Mystery links are not on this site right now. |
| unknown_field | 400 | every plan | A field the endpoint doesn't take (a link field too): the message names it. |
| bad_items, bad_token, unknown_token, bad_amount, below_minimum | 400 | make | An item is missing, twice, not a token a mystery link takes or not dollars of at least $0.01. |
| bad_prizes | 400 | make | Not ladder, jackpot or a list of up to 16 { usd, count } that adds up to the items' dollars and link.boxes, or too many boxes for the pool. |
| prize_too_small | 400 | make | The smallest prize holds less than a box's minimum of a token: raise the pool or pick fewer boxes. |
| bad_pay, bad_note, bad_design | 400 | make | That field breaks its rule above (a sticker the chain does not draw yet is bad_design). |
| bad_who, bad_list, bad_time | 400 | make | A link field breaks its rule, closesAt is null or 0 or claims close before they open. |
| bad_link_key, link_key_used | 400 | make | The link key is your wallet's, used on Base or another link's key: make a fresh one. |
| token_not_allowed, not_buyable, no_price | 400 or 409 | make | A token can't go in a mystery link or be bought right now. |
| token_paused, pool_not_listed | 409 | make | That stock is paused or its pool can't be bought through right now: try again later. |
| price_moved, fee_changed, draw_fee_changed | 409 | make | Prices, the fee or the draw fee moved: build the plan again. |
| paused, verified_off | 409 | make, claim | New mystery links are paused or verified-only links are off right now. |
| insufficient_balance | 409 | make | The wallet holds less USDC or ETH than the plan takes at most. |
| rate_limited | 429 | make | Too many wallet lists or new notes in a day: wait as long as the message says. |
| no_mystery_link | 404 | claim, take back, read | No mystery link with that poolId. |
| none_left, not_open_yet, claims_closed, already_claimed | 409 | claim | Nothing to claim for this wallet right now. |
| not_verified, not_on_list | 403 | claim | This link is for verified wallets or a list. |
| list_unknown, not_claimable_here, claim_refused | 409 or 4xx | claim | This link's gate is not one this site serves or its check refused this claim: the message says why. |
| approval_expired, bad_approval | 409 | claim | A verified-only link's approval ran out or did not hold: ask for the claim again. |
| bad_signature, bad_link_signature | 400 | claim | Not 65 bytes or not the link key's signature over this typed data (a link given a new key has a new one). |
| try_again | 409 | claim, open | drand's next round is already out by Base's clock: build the plan again in a few seconds. |
| bad_ids, no_box | 400 or 404 | open | ids is not 1 to 50 box ids or a box does not exist. |
| not_holder | 403 | open | The box is not in this wallet. |
| not_sealed, open_closed | 409 | open | The box is opened already, its link was taken back or it ended more than 30 days ago. |
| not_creator | 403 | take back | Only the link's maker takes back. |
| still_open, nothing_free, none_left, taken_back | 409 | take back | Claims are still open, nothing has come free yet, every box is claimed and drawn or everything left was taken back. |
| bad_number | 400 | read | poolId is not a whole number from 1. |
| would_revert | 409 | every plan | The mystery link contract would refuse it, named where it can be. |
The codes every endpoint shares are on Requests, plans and errors.