@binance/w3w-multichain-connector
The @binance/w3w-multichain-connector package provides a wrapper for the Binance Wallet extension multichain connector.
Installation
pnpm add @binance/w3w-multichain-connector
# or
npm install @binance/w3w-multichain-connector
Usage
Importing
import { getMultichainWallet } from '@binance/w3w-multichain-connector'
Get Wallet Instance
const wallet = getMultichainWallet()
if (!wallet) {
console.log('Binance Wallet extension not installed')
}
Check Extension Installed
import { checkExtensionInstalled } from '@binance/w3w-multichain-connector'
const isInstalled = checkExtensionInstalled()
Check Extension Feature Support
import { checkExtensionSupported, Features } from '@binance/w3w-multichain-connector'
const isSupported = checkExtensionSupported(Features.requestConnect)
Connect Wallet
const connectedWallets = await wallet.requestConnect(['56', 'CT_501'])
Connect with SAS
// Single wallet SAS
const { wallet: connectedWallet, aggreeEnableSAS } = await wallet.requestConnectWithSAS({
binanceChainIds: ['56'],
userId: 'user-id',
enabledWalletInfo: [
{ walletType: 'SEED_PHRASE', chain: 'evm', userPublicKeyHex: '0x...' }
]
})
// Multi wallet SAS
const { walletList, enabledWalletIds, connectId } = await wallet.requestConnectWithMultiWalletSAS({
binanceChainIds: ['56'],
userId: 'user-id'
})
Check Connected Wallets
const wallets = await wallet.checkConnectedWallet()
// The user's active wallet will be the first element in the array
Get Wallet Info
const walletInfo = await wallet.getWalletInfo('0x...address', '56')
Switch Chain
await wallet.switchChain('56')
Disconnect
// Disconnect all wallets
await wallet.disconnect()
// Disconnect specific accounts
await wallet.disconnectWallets(['account-id-1', 'account-id-2'])
Sign Order
const signature = await wallet.signOrder({
walletId: 'wallet-id',
walletAddress: '0x...',
binanceChainId: '56',
txData: '...',
feeAmount: '0.001',
feeAmountLevel: 'Medium', // 'Low' | 'Medium' | 'High' | 'Custom'
digest: '...',
digestSign: '...'
})
Auto Sign
await wallet.requestAutoSign()
console.log('Auto sign enabled:', wallet.autoSignEnabled)
SAS Operations
// Enable SAS
const { aggreeEnableSAS } = await wallet.requestEnableSAS({
walletId: 'wallet-id',
userId: 'user-id',
userEmail: '[email protected]'
})
// Enable multi-wallet SAS
const { enabledWalletIds } = await wallet.requestEnableMultiWalletSAS({
walletIds: ['wallet-1', 'wallet-2'],
userId: 'user-id',
userEmail: '[email protected]'
})
// Get SAS Keyshare
const keyshares = await wallet.getSASKeyshare({
walletIds: ['wallet-id'],
userId: 'user-id',
spsVersion: '1.0',
isSilent: false // if true, won't prompt unlock when wallet is locked
})
// Sync SAS Status
await wallet.syncSASStatus({
userId: 'user-id',
statusList: [
{ walletId: 'wallet-id', enabled: true }
]
})
// Get ProofKey Signature (before placing order)
const { timeStamp, proofKeyPublicKey, timestampSignature } = await wallet.getSASProofKeySignature({
walletId: 'wallet-id',
userId: 'user-id'
})
// Get Connected Wallets with ProofKey
const walletsWithProofKey = await wallet.getConnectedWalletAndProofKey({
userId: 'user-id'
})
Handle Events
const wallet = getMultichainWallet()
// Wallet lock status changed
wallet.on('walletLockedChanged', (isLocked) => {
console.log('Wallet locked:', isLocked)
})
// Auto sign status changed
wallet.on('autoSignEnabledChanged', (isEnabled) => {
console.log('Auto sign enabled:', isEnabled)
})
// Connected wallets changed
wallet.on('connectedWalletsChanged', (connectedWallets) => {
console.log('Connected wallets:', connectedWallets)
})
// Connected chain changed
wallet.on('connectedChainIdChanged', (binanceChainId) => {
console.log('Chain changed:', binanceChainId)
})
Properties
| Property | Type | Description |
version | string | Current extension version |
autoSignEnabled | boolean | Whether auto sign is enabled |
walletLocked | boolean | Whether the wallet is locked |
extensionId | string | Extension unique identifier |
Types
IConnectedWallet
| Field | Type | Description |
walletIcon | string | Wallet icon (base64) |
walletName | string | Wallet name |
walletId | string | Wallet unique identifier |
walletType | WalletType | Wallet type (privateKey / seedPhrase) |
addressList | Array<{ address, binanceChainId, publicKeyHex }> | Wallet address list |
groupID? | string | Wallet group ID |
groupName? | string | Wallet group name |
WalletType
| Value | Description |
privateKey | Private key wallet |
seedPhrase (hd) | Seed phrase (mnemonic) wallet |
Features
| Value | Description |
| Connect | |
requestConnect | Connect wallet |
requestConnectWithSAS | Connect wallet with single-wallet SAS |
requestConnectWithMultiWalletSAS | Connect wallet with multi-wallet SAS |
checkConnectedWallet | Check connected wallets |
getWalletInfo | Get wallet info by address and chain |
disconnect | Disconnect all wallets |
disconnectWallets | Disconnect specific wallets |
switchChain | Switch chain |
| SAS | |
requestEnableSAS | Request enable SAS (single wallet) |
requestEnableMultiWalletSAS | Request enable SAS (multi wallet) |
getSASKeyshare | Get SAS keyshare |
syncSASStatus | Sync SAS status |
getConnectedWalletAndProofKey | Get connected wallets with ProofKey |
getSASProofKeySignature | Get ProofKey signature before placing order |
| Signing | |
requestAutoSign | Request auto sign |
signOrder | Sign transaction order |
| Events | |
eventWalletLockedChanged | Wallet lock status changed event |
eventAutoSignEnabledChanged | Auto sign status changed event |
eventConnectedWalletsChanged | Connected wallets changed event |
eventConnectedChainIdChanged | Connected chain changed event |