Skip to content

Add examples/ folder with runnable usage scripts#8

Merged
pimfeltkamp merged 2 commits intomainfrom
add-examples-folder
Apr 28, 2026
Merged

Add examples/ folder with runnable usage scripts#8
pimfeltkamp merged 2 commits intomainfrom
add-examples-folder

Conversation

@pimfeltkamp
Copy link
Copy Markdown
Contributor

Summary

Adds five self-contained TypeScript examples for the most common usage patterns. Each script is one file, reads its bearer token from CRYPTOHOPPER_TOKEN, and runs with npx tsx <file>.ts.

File What it shows
public-ticker.ts Public endpoint, no token, single ticker fetch
whoami.ts Minimal authenticated request
list-hoppers.ts List resource with optional filter
error-handling.ts CryptohopperError codes / status / retryAfterMs / serverCode
start-backtest.ts Long-running async resource — submit, poll, render result

Why

Currently a new user lands on the README, gets a Quickstart snippet, and has no working file they can git clone && cd && npx tsx into. Every adjacent SDK ecosystem (Stripe, Twilio, Supabase) ships an examples/ folder for exactly this reason. This is the missing on-ramp.

Layout

  • examples/package.json is a separate workspace pinning @cryptohopper/sdk + tsx + typescript@6 + @types/node@25. It does not affect the SDK's published surface.
  • examples/tsconfig.json typechecks the scripts in strict mode against the built dist/ typings. Verified clean (tsc --noEmit exit 0).
  • examples/.gitignore keeps node_modules/ and a per-folder package-lock.json out of git.

Test plan

  • tsc --noEmit exits 0 for every example
  • node --experimental-strip-types --check passes on every example
  • (manual) CRYPTOHOPPER_TOKEN=… npx tsx whoami.ts runs end-to-end against prod
  • (manual) npx tsx public-ticker.ts works without any token

pimfeltkamp and others added 2 commits April 25, 2026 23:23
Five self-contained TypeScript examples covering the most common
usage patterns: a public unauthenticated ticker fetch, an
authenticated whoami, listing hoppers with optional filter, the
typed CryptohopperError surface, and a 30-day backtest with
polling. Each script is stand-alone and reads its bearer token
from CRYPTOHOPPER_TOKEN.

Includes a sub-package.json pinning @cryptohopper/sdk + tsx,
a strict tsconfig (typechecked clean against the SDK source),
and a short examples/README.md explaining how to run them. Main
README now points at the folder from the Quickstart section.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The original example used apiKey: '' on the assumption that
public market-data endpoints accept anonymous calls. Two issues:

1. The SDK throws TypeError on empty apiKey at construction.
2. Even with any token, the API gateway requires a real OAuth
   bearer on every call — there are no anonymous routes.

So the example crashed at line 1 (SDK validation) before ever
hitting the wire. Renames the file to drop the 'public-' prefix
that no longer makes sense, and updates the example to read
CRYPTOHOPPER_TOKEN like every other example in this folder.

Same auth-claim cleanup that landed across SDK READMEs and
wikis from cryptohopper-resources#9.
@pimfeltkamp
Copy link
Copy Markdown
Contributor Author

Pushed a follow-up commit renaming public-ticker.ts to ticker.ts. The original example called new CryptohopperClient({ apiKey: "" }) — that throws a TypeError because the SDK validates apiKey at construction, and the API gateway has no anonymous routes anyway. The renamed version reads CRYPTOHOPPER_TOKEN like every other example. Same false-claim cleanup that landed in resources#9. Diff is 1 file added, 1 deleted, 3-line README touch-up. No re-review needed beyond confirming the rename.

@pimfeltkamp pimfeltkamp merged commit 08be696 into main Apr 28, 2026
1 check passed
@pimfeltkamp pimfeltkamp deleted the add-examples-folder branch April 28, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant