Authentication
All requests to the Trust Wallet API are authenticated with an API access ID and an HMAC-SHA256 signature derived from your HMAC secret.
Getting credentials
Sign in at portal.trustwallet.com
Create an app, then create an API key inside it
Copy your Access ID and HMAC Secret — the secret is shown only once
Configuring the CLI
The recommended approach is twak init, which stores credentials in ~/.twak/credentials.json with 0600 permissions:
twak init --api-key your_access_id \
--api-secret your_hmac_secretFor CI/CD pipelines, use environment variables:
export TWAK_ACCESS_ID=your_access_id
export TWAK_HMAC_SECRET=your_hmac_secretDo not add these exports to shell config files (
~/.zshrc,~/.bashrc). Usetwak initfor persistent local credentials. Env vars are intended for ephemeral CI/CD environments where secrets are injected at runtime.
How HMAC signing works
Every API request is signed with HMAC-SHA256 over six fields concatenated together:
METHOD
HTTP method in uppercase — GET, POST, DELETE
PATH
URL path without query string — /v1/wallet/balance
QUERY
Query string (without leading ?), or empty string
ACCESS_ID
Your API access ID
NONCE
Unique random string — prevents replay attacks
DATE
ISO 8601 timestamp — validated within a ±5 min window
The resulting base64 signature is sent in the Authorization header. Four headers are required on every request:
X-TW-Credential
Your API access ID
X-TW-Nonce
The nonce used in signing
X-TW-Date
The timestamp used in signing
Authorization
Base64-encoded HMAC-SHA256 signature
The CLI and TypeScript SDK handle signing automatically — you only need to understand this if you are making raw HTTP calls.
Raw HTTP example
Security best practices
Use
twak initfor local credentials — stores in~/.twak/credentials.jsonwith restricted permissionsUse
twak wallet keychain saveto store the wallet password in the OS keychain (macOS Keychain / Linux Secret Service)Never commit your HMAC secret to version control — add
.envto.gitignoreNever add credentials to shell config files (
~/.zshrc,~/.bashrc) — usetwak initinsteadRotate keys regularly from the developer portal
Use separate keys for development and production
Last updated
Was this helpful?