With the transition to a modularized structure, the Binance Connector has been split into separate NPM libraries, each focusing on a distinct product (e.g., Mining, Futures, etc.). This guide explains how to migrate from the monolithic @binance/connector (or @binance/connector-typescript) package to the new @binance/mining library.
-
Package Name:
The modularised Mining Connector has been moved to a new package:Old:
@binance/connector
New:@binance/mining -
Installation:
Uninstall the old package and install the new one:npm uninstall @binance/connector npm install @binance/mining
-
Imports:
Update your import paths.Old:
import { Spot } from '@binance/connector';
New:
import { Mining } from '@binance/mining';
-
Configuration and Client Initialization:
The new structure keeps the existing configuration options but modularizes clients intoMiningRestAPI.Old:
const client = new Spot({ apiKey: 'your-key', apiSecret: 'your-secret' }); client.<method_name>().then(console.log);
New:
import { Mining, MiningRestAPI } from '@binance/mining'; const configurationRestAPI = { apiKey: 'your-key', apiSecret: 'your-secret', }; const client = new Mining({ configurationRestAPI }); client.restAPI.<method_name>().then(console.log);
-
Examples and Documentation:
Updated examples can be found in the new repository folders:- REST API:
examples/rest-api/ - WebSocket API:
examples/websocket-api/ - WebSocket Streams:
examples/websocket-streams/
- REST API:
Remove the old package from your project:
npm uninstall @binance/connectorInstall the new Mining-specific package:
npm install @binance/miningReplace all occurrences of:
import { Spot } from '@binance/connector';With:
import { Mining } from '@binance/mining';Adjust your code to use the modularized structure. For example:
Old:
const client = new Spot({ apiKey: 'your-key', apiSecret: 'your-secret' });New:
import { Mining, MiningRestAPI } from '@binance/mining';
const configurationRestAPI = {
apiKey: 'your-key',
apiSecret: 'your-secret',
};
const client = new Mining({ configurationRestAPI });Run your application to ensure everything works as expected. Refer to the new documentation for any advanced features or configuration options.
- Future Modular Packages: Similar packages for other products (e.g., Wallet, Staking) will follow this pattern.