==========
- Use the present tense ("Add feature" not "Added feature") and the imperative mood ("Move class to..." not "Moves class to...") on commits and use the name issue on pull requests.
- Pull requests must be reviewed before merged.
- Done is better than perfect. Does it work as expected? Ship now, iterate later.
- All contributions must have tests. Remember to verify the Github Actions CI status.
- Every commit is checked using Github Actions.
- If the CI status are not passing, the deploy will not work.
- CSS: https://github.com/airbnb/css
- Javascript: https://github.com/airbnb/javascript
- Vue: https://vuejs.org/style-guide/
- GitHub Issues is used to track all tasks that needed to be done.
- Kadscan board is used to get a decent look on what's going on wright now.
- Every two weeks all done tasks are put together in a Milestone and the current Sprint is closed.
Here's a brief overview of the structure:
.
├── components # Global reusable components
├── composables # Composables for reactive logic
├── config # Configuration files specific to Nuxt
├── layouts # Layout templates for different parts of the application
├── plugins # Plugins extending Nuxt's core functionality
├── pages # Vue components that define each page of the application
├── app.config.ts # Central application configurationKadscan is powered by Nuxt.
If you have any problems configuring your enviroment, remember to read the Nuxt Documentation.
- Clone the repository:
$ gh repo clone hack-a-chain-software/indexer-kadena
$ cd indexer-kadena- Check all packages and copy the .env.example file and edit it with your environment config:
$ cp ./front/.env.example ./front/.env- Install frontend dependencies via PNPM
$ pnpm installWhen working on frontend, run pnpm web dev. Files will be compiled, concatenated and the browser will auto update.
Tests (npm test) need Node 22.18 or newer, because they run TypeScript files directly.
The Dockerfile builds Kadscan from source (npm ci && npm run build) and runs the resulting .output as the unprivileged node user on port 3000.
Some settings are read by nuxt.config.ts while building, so they are baked into the image. Pass them as build arguments. None has a default in the Dockerfile, and an argument you leave out falls back to the default in nuxt.config.ts:
| Build argument | Purpose |
|---|---|
KADINDEXER_MAINNET_API_URL, KADINDEXER_MAINNET_API_KEY |
Mainnet indexer GraphQL endpoint and API key |
KADINDEXER_TESTNET_API_URL, KADINDEXER_TESTNET_API_KEY |
Testnet indexer GraphQL endpoint and API key |
CG_KEY, CG_IS_DEMO_API_KEY, CG_URL |
CoinGecko API key, whether it is a demo key, and base URL. Server-only: they are never sent to the browser. With no CG_URL, a Pro key goes to pro-api.coingecko.com and a demo key or no key to api.coingecko.com. Prefer setting these at runtime instead (see below) |
Build arguments end up in the image build history and in the built output, so keep images built with keys private.
A CoinGecko key passed as a build argument is compiled into the server bundle (.output/server), and so into every layer of the image. Leave it out of the build and set it when the container starts instead. Nuxt reads the CoinGecko settings from the environment at runtime under these names:
docker run -e NUXT_CG_KEY=... -e NUXT_CG_IS_DEMO_API_KEY=true -e NUXT_CG_URL=https://api.coingecko.com/api/v3 -p 3000:3000 kadscanA runtime NUXT_CG_* value overrides the value from the build.
docker build \
--build-arg KADINDEXER_MAINNET_API_URL=https://indexer.example.com/graphql \
-t kadscan .The browser never calls CoinGecko directly: it posts to /api/coingecko, and the server makes the call. The proxy accepts only the requests Kadscan itself makes (coins/kadena, coins/kadena/market_chart and coins/kadena/market_chart/range, in US dollars) and answers anything else with 400.
The proxy never makes a page wait on a slow upstream and never shows an old price as current:
- Cache. Answers are cached in memory: 60 seconds for
coins/kadena, 10 minutes for the 14-day chart and for today's price range, and 24 hours for a past day's range, which no longer changes.coins/kadenahas its own slot; charts share at most 200 entries. Only well-formed answers are cached:coins/kadenaneeds a positivemarket_data.current_price.usd, and charts need a non-emptypriceslist of positive[time, price]pairs. A range may start no earlier than 2019-11-05, Kadena's first trading day. - Stale-while-revalidate. Once a copy is past that time, it is still answered at once while one background request refreshes it: for
coins/kadenauntil its data is 15 minutes old (counted from CoinGecko'slast_updated, or the fetch time if it has none), and for charts, which are historical, up to 24 hours. - Timeouts and circuit breakers. CoinGecko gets 3 seconds and the rates document 2 seconds. There are two breakers, one for
coins/kadenaand one for the charts, so chart traffic can never hold back the live price. A breaker trips only on a network error, a timeout, a 5xx or a429: it then skips CoinGecko for 30 seconds, doubling on each failure in a row up to 5 minutes, or longer if a429asks for it withRetry-After. Calls already in flight when it trips do not count again. While it is open, requests are answered straight from the cache, the fallback, or503. Once it expires, a single trial request runs in the background and requests are still answered at once until it succeeds. A rates failure is held for 30 seconds. - Chart budget. Chart requests to CoinGecko are limited to about 20 a minute (
coins/kadenais not counted). When the budget is used up, a chart is answered from the cache if there is a copy, otherwise at once with503and a shortRetry-After; no request waits for the budget. - Unusable answers. A
200CoinGecko cannot fill (an empty body, or an emptypriceslist for a day with no trading) and a4xxother than429count against that one request only: it is not sent again for 10 minutes, any older copy is kept, and neither breaker counts it. - Fallback. With no CoinGecko copy whose data is younger than 15 minutes,
coins/kadenais built from the ZelCore rates document (price, 24-hour change and market cap). With no copy at all, the fallback starts 1 second into the CoinGecko call and the first usable answer is returned. The rates document has no update time, so itsasOfis when the proxy first saw that price, and a Kadena price unchanged for 15 minutes or more is treated as frozen and not served. With neither, the answer is503, and the pages show no price. The 14-day chart comes from Binance first and from this proxy only if Binance fails; charts have no rates fallback.
Each answer is CoinGecko's body plus two extra top-level fields the pages do not read: asOf, the ISO time of the upstream data, and source (fresh, miss, stale or fallback). The same values are in the x-kadscan-as-of and x-kadscan-cache headers.
This variable is read at runtime, so set it on the container:
| Variable | Required | Meaning |
|---|---|---|
ZELCORE_RATES_URL |
no | Rates document used as the coins/kadena fallback. Defaults to https://viprates.zelcore.io/v2/rates. |
When Kadscan runs as an explorer hosted by Flux, it can show a banner and a short list of articles supplied by a content feed. The feature is off by default: with HOSTED_BY_FLUX unset, the server never fetches the feed and no extra markup is rendered.
These variables are read at runtime, so set them on the container, not at build time:
| Variable | Required | Meaning |
|---|---|---|
HOSTED_BY_FLUX |
no | Set to exactly true to turn the feature on. Any other value, or no value, leaves it off. |
EXPLORER_CONTENT_URL |
when on | Full https: URL of the feed, including the coin query parameter. If it is missing, not https:, or has no valid coin, the feature stays off and one line is logged. |
EXPLORER_CONTENT_CACHE |
no | File path where the last good feed is saved, so content survives a restart while the feed is unreachable. The directory is not created for you; it must exist and be writable by the node user. |
The feed is fetched at start-up and then every 5 minutes. If it cannot be fetched, the last good content keeps being shown (from memory or the cache file); content older than 24 hours is hidden, and with no good content yet the sections are simply absent. Content refreshes on page load.
docker run -d --name kadscan -p 3000:3000 \
-e HOSTED_BY_FLUX=true \
-e EXPLORER_CONTENT_URL="https://dashboard.example.com/api/public/explorer/v1/config?coin=kda" \
-e EXPLORER_CONTENT_CACHE=/data/explorer-content.json \
-v kadscan-data:/data \
kadscanThe image creates /data owned by the node user, so a new named volume mounted there is writable. For a bind mount or another path, make sure the directory exists and the node user (uid 1000) can write to it.