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#

FieldTypeDescription
bytesstringThe built transaction in base64, up to 20,000 characters
signaturestringThe recipient’s signature, up to 20,000 characters
Request body
{
  "bytes": "AAACAQ…",
  "signature": "BQNN…"
}

Never send the link’s private key. The server has no use for it.

Checks, in order#

  1. Claiming is configured on this deployment.
  2. Both fields are strings within the length limit.
  3. The transaction has a sender and exactly one command, a call to this package’s escrow::claim_escrow.
  4. A simulation succeeds.
  5. Enoki accepts it, with the call target and receiving addresses restricted.

Responses#

200 OK
{ "digest": "9vT3…" }
409 Conflict
{ "error": "Try the claim again.", "code": "stale" }
StatusMeaningRetry
200The claim ran. The digest identifies the transaction.No
400The body or the transaction is not a valid claim.No
409With code stale: the sponsor’s details changed.Rebuild and sign again
409Without a code: the escrow was claimed, refunded or has expired.No
502Sui or Enoki failed, or the sponsor is out of funds.Yes, after a moment
503Claiming isn’t set up on this deployment.No

Example#

claim.ts
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.

200 OK
{ "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.

503 Service Unavailable
{ "error": "Live prices are unavailable" }

GET /api/impact#

Returns what claims have sent to the water treasury. See How the totals are counted.

200 OK
{
  "donated": { "SUI": "2000000", "LOFI": "0" },
  "roundups": 2,
  "claims": 2,
  "complete": true
}
FieldTypeDescription
donatedobjectBase units received by the treasury, by token
roundupsnumberClaims that paid a roundup
claimsnumberAll claims of this contract
completebooleanFalse 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.