Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sdks/binance/docs/guides/api-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ node --env-file=.env account.mjs

A successful request prints `Account access verified.` and the number of returned balances. See [`getAccountInformation()`](/api/classes/MainClient#getaccountinformation) and [Error handling](/guides/errors) if the request fails.

## Ed25519 keys

Binance also accepts a self-generated Ed25519 key. In API Management, choose a self-generated key, register the public key, and keep the private key PEM on the server.

Pass the PEM contents as `api_secret`. The SDK recognises an Ed25519 or RSA private key from the PEM and signs with it. Load the key from a file so the PEM stays out of `.env`:

<<< @/../examples/ed25519-client.ts

The same `api_secret` option works on `USDMClient`, `WebsocketClient` and `WebsocketAPIClient`. `session.logon` on the WebSocket API uses an Ed25519 key.

## Testnet and demo keys

- Spot Testnet: create the key at [Spot Testnet](https://testnet.binance.vision/) and set `testnet: true` on `MainClient` and any Spot WebSocket clients. See [Spot Testnet](/guides/testing-environments#spot-testnet).
Expand Down
13 changes: 13 additions & 0 deletions sdks/binance/examples/ed25519-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readFileSync } from 'node:fs';
import { MainClient } from 'binance';

const api_key = process.env.BINANCE_API_KEY;
const secretPath = process.env.BINANCE_API_SECRET_PATH;
if (!api_key || !secretPath) {
throw new Error('Set BINANCE_API_KEY and BINANCE_API_SECRET_PATH.');
}

export const client = new MainClient({
api_key,
api_secret: readFileSync(secretPath, 'utf8'),
});