Skip to content
Retr0 Academy
Advanced JavaScript

Advanced JavaScript · 5 min read

Mini App: NEAR Account Explorer

Build a small app that reads live NEAR testnet data over JSON-RPC: state, validation, loading and error UI, caching, and race-condition handling.

Time to combine everything: modules-style organisation, async fetch with timeouts, closures for caching, delegated events and safe rendering. The app looks up any testnet account and shows its balance, storage, and whether it holds a Retr0 Academy diploma, all over raw JSON-RPC, which is what near-api-js does under the hood.

Every call in this app is a free view call: no wallet, no gas.
Every call in this app is a free view call: no wallet, no gas.

The plan

  1. Validate the account id before hitting the network.
  2. view_account: balance (in yoctoNEAR) and storage usage.
  3. call_function → verify_diploma: arguments are base64 JSON, the result is an array of bytes holding JSON.
  4. Cache results in a closure-backed Map.
  5. Ignore stale responses if the user searches again before the first finishes.
NEAR account explorer (live testnet)
<form id="f">
<input id="acct" value="hackathon-judge.retr0school.testnet" aria-label="Testnet account" spellcheck="false">
<button>Look up</button>
</form>
<div class="chips">
<button data-acct="demo-learner.retr0school.testnet">demo-learner</button>
<button data-acct="diploma.retr0school.testnet">diploma contract</button>
<button data-acct="nobody-here-xyz.testnet">missing account</button>
</div>
<section id="out" aria-live="polite"></section>

Edit this example in the Playground.

Open in Playground

What each technique does here

TechniqueWhere
Validation before networkACCOUNT_RE.test(account)
Parallel requestsPromise.all([view_account, verify_diploma])
TimeoutAbortSignal.timeout(8000)
BigInt for moneyyoctoToNear: 1 NEAR = 10^24 yocto, beyond Number precision
Closure cache that forgets failurescached
Race-condition guardthe latest ticket
Event delegationone listener on .chips
XSS-safe renderingtextContent in row()

Summary

You built a real client for a public blockchain API with nothing but the platform. Every NEAR front end, from wallets to explorers, is these same pieces with more polish.

Open in Playground

Saved in this browser.