Reference
HTTP API
The routes the app serves: claim sponsorship, live prices and water totals.
On this page
Before you use it#
POST /api/claim#
Pays the gas for one claim and runs it. The caller builds and signs the transaction first, with Enoki’s sponsor set as the gas owner.
Request#
| Field | Type | Description |
|---|---|---|
| bytes | string | The built transaction in base64, up to 20,000 characters |
| signature | string | The recipient’s signature, up to 20,000 characters |
{
"bytes": "AAACAQ…",
"signature": "BQNN…"
}Never send the link’s private key. The server has no use for it.
Checks, in order#
- Claiming is configured on this deployment.
- Both fields are strings within the length limit.
- The transaction has a sender and exactly one command, a call to this package’s
escrow::claim_escrow. - A simulation succeeds.
- Enoki accepts it, with the call target and receiving addresses restricted.
Responses#
{ "digest": "9vT3…" }{ "error": "Try the claim again.", "code": "stale" }| Status | Meaning | Retry |
|---|---|---|
| 200 | The claim ran. The digest identifies the transaction. | No |
| 400 | The body or the transaction is not a valid claim. | No |
| 409 | With code stale: the sponsor’s details changed. | Rebuild and sign again |
| 409 | Without a code: the escrow was claimed, refunded or has expired. | No |
| 502 | Sui or Enoki failed, or the sponsor is out of funds. | Yes, after a moment |
| 503 | Claiming isn’t set up on this deployment. | No |
Example#
import { EnokiClient } from "@mysten/enoki/client";
import { toBase64 } from "@mysten/sui/utils";
import { ENOKI, NETWORK } from "@/lib/chain/config";
import { dAppKit } from "@/lib/chain/dappKit";
import { buildClaim, suiClient } from "@/lib/chain/escrow";
const transaction = await buildClaim(escrow, privateKey, recipient);
// Makes Enoki's sponsor the gas owner
await new EnokiClient({ apiKey: ENOKI.publicKey }).prepareSponsoredTransaction({
transaction,
network: NETWORK,
});
const built = await transaction.build({ client: suiClient });
const signed = await dAppKit.signTransaction({ transaction: toBase64(built) });
const res = await fetch("/api/claim", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ bytes: signed.bytes, signature: signed.signature }),
});GET /api/prices#
Returns the dollar price of one token. See Prices and tokens for the sources.
{ "SUI": 0.6764, "LOFI": 0.0042 }The numbers above only show the format. A 200 response may be shared by a CDN for 15 seconds.
{ "error": "Live prices are unavailable" }GET /api/impact#
Returns what claims have sent to the water treasury. See How the totals are counted.
{
"donated": { "SUI": "2000000", "LOFI": "0" },
"roundups": 2,
"claims": 2,
"complete": true
}| Field | Type | Description |
|---|---|---|
| donated | object | Base units received by the treasury, by token |
| roundups | number | Claims that paid a roundup |
| claims | number | All claims of this contract |
| complete | boolean | False while older claims are still being read |
Refreshed at most once a minute. If Sui can’t be reached, the last totals are kept for 10 minutes. After that it answers 503.