Your first call
A complete client. Copy it, set your Key ID, run it.
You need Node.js 22 or later, a registered key (Generate keys), and
megtrust-private.pem in the working directory.
Client
Save the signing function from Sign a request as call.mjs.
It points at the sandbox; for production set BASE to https://vault.megtrust.com.
Use it
import { call } from "./call.mjs";
const { status, body } = await call("GET", "/api/v1/wallets");
console.log(status, body.data);MEGTRUST_KEY_ID=YOUR_KEY_ID node first-call.mjsA 200 with an empty data array still means success — it proves your signing is correct, which is
the part worth getting right first.
Or use the supplied client
The downloadable client.mjs does the same signing with more
guard rails: it refuses non-HTTPS origins, paths outside /api/v1/, and a payout without an
idempotency key. It uses Node's standard library and needs no install.
mkdir megtrust-integration
cd megtrust-integration
curl --fail --show-error https://docs.megtrust.com/integrations/megtrust/client.mjs --output client.mjs
export MEGTRUST_BASE_URL=https://stagingvault.megtrust.com
export MEGTRUST_KEY_ID=YOUR_KEY_ID
export MEGTRUST_PRIVATE_KEY_PATH=/absolute/path/megtrust-private.pemMEGTRUST_BASE_URL is the origin only — do not append /api/v1.
import { clientFromEnv } from "./client.mjs";
const api = clientFromEnv();
const result = await api.request("GET", "/api/v1/wallets");
if (result.status !== 200) throw new Error(JSON.stringify(result));
console.log(result.body.data);Run node example.mjs. Each result has { status, body, requestId, retryAfter }. HTTP error responses
are returned with their status; transport failures throw. No call is automatically retried.
Next
- Receive funds — show the right deposit address.
- Send a payout — request, follow and recover a payout.
- Errors — the closed set of error codes to branch on.