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., Staking, Futures, etc.). This guide explains how to migrate from the monolithic @binance/connector (or @binance/connector-typescript) package to the new @binance/staking library.
-
Package Name:
The modularised Staking Connector has been moved to a new package:Old:
@binance/connector
New:@binance/staking -
Installation:
Uninstall the old package and install the new one:npm uninstall @binance/connector npm install @binance/staking
-
Imports:
Update your import paths.Old:
import { Spot } from '@binance/connector';
New:
import { Staking } from '@binance/staking';
-
Configuration and Client Initialization:
The new structure keeps the existing configuration options but modularizes clients intoStakingRestAPI.Old:
const client = new Spot({ apiKey: 'your-key', apiSecret: 'your-secret' }); client.<method_name>().then(console.log);
New:
import { Staking, StakingRestAPI } from '@binance/staking'; const configurationRestAPI = { apiKey: 'your-key', apiSecret: 'your-secret', }; const client = new Staking({ 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/
- REST API:
Remove the old package from your project:
npm uninstall @binance/connectorInstall the new Staking-specific package:
npm install @binance/stakingReplace all occurrences of:
import { Spot } from '@binance/connector';With:
import { Staking } from '@binance/staking';Adjust your code to use the modularized structure. For example:
Old:
const client = new Spot({ apiKey: 'your-key', apiSecret: 'your-secret' });New:
import { Staking, StakingRestAPI } from '@binance/staking';
const configurationRestAPI = {
apiKey: 'your-key',
apiSecret: 'your-secret',
};
const client = new Staking({ 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.