Skip to main content
Every example in these guides calls the same small client. This page is that client, in Python, Node and Go. Copy it once and each guide fits in three to eight lines.

The surface every guide assumes

It reads three environment variables — HEVN_API, HEVN_KEY_PEM and HEVN_EMAIL — set up in the Quickstart. Nothing below hardcodes a host. HEVN_API ends in /dapi/v1 (https://sandbox-api.hevn.finance/dapi/v1); the old /v1 base answers 404 rather than redirecting, so a helper that asserts the suffix at start-up turns a whole run of mystery 404s into one clear failure.
In the Go tabs the client is a variable called api and hevn is the package: api.Post(…) is a call on your client, hevn.Body{…} is a type from the package. Naming the variable hevn shadows the package and stops the file compiling.

Binding an account

acting_as is the only thing that sets X-Hevn-Account, and three kinds of route read it differently: The middle row is the one that changes how you use the client. There is no client id in any path any more, so reading your own account means binding your own cl_… too — the userId the login answered:
An unbound client calling /client* sends no header at all, which is a 422 validation_failed with details.location: "header" and X-Hevn-Account in details.fields — not a read of your own account. A bound client calling POST /clients or any escrow route is the mirror image, 400 account_scope_conflict with details.reason: "selfScopedRoute", so keep the unbound client for those.

Install

Load the developer key

The private half comes from HEVN_KEY_PEM and never leaves the process.

Sign bytes

Two functions, used by login and by every payment: ECDSA P-256 over SHA-256, DER-encoded, base64 out. Signing is why each rule is there.

Wrap the key

The guides call key.sign_payload(...) and read key.public_key. That is these two functions bound to one loaded key.

Log in

Two calls, two signatures. The result is an access token good for an hour and a refresh token good for sixty days — see Sessions.

Hold the session

One object owns the tokens and re-mints the access token on demand, so the request layer below never thinks about expiry.

Send a request

One place turns the error envelope into a typed error, honours Retry-After on a 429, re-mints once on a 401, and adds X-Hevn-Account when the client is bound.

Download an export

GET /dapi/v1/transactions/export streams a file rather than JSON, so it gets its own method: same headers, same typed error, bytes to disk instead of a parsed body.

Confirm until it settles

The whole retry policy as one method: already_funded is success, funding_attempt_expired means re-open, a 202 and the bundler codes mean confirm again, anything else propagates.

Poll a read

Client provisioning, KYB review, rail activation and payin settlement all end in a read that changes on someone else’s clock.

The Go plumbing

Python and Node are complete above. Go’s helpers are worth spelling out once.
Go

Put it together

Back to the Quickstart

Nine steps in the sandbox, from an empty account to money that moved on chain.