@tronweb3/tronwallet-adapter-binance
v1.0.3
Published
Wallet adapter for Binance Wallet app on Android and iOS
Readme
@tronweb3/tronwallet-adapter-binance
This package provides an adapter to enable TRON DApps to connect to the Binance Wallet.
Demo
import { BinanceWalletAdapter } from '@tronweb3/tronwallet-adapter-binance';
const adapter = new BinanceWalletAdapter();
// connect to BinanceWallet
await adapter.connect();
// then you can get address
console.log(adapter.address);
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
});
// create a send TRX transaction
const unSignedTransaction = await tronWeb.transactionBuilder.sendTrx(
targetAddress,
100,
adapter.address
);
// using adapter to sign the transaction
const signedTransaction = await adapter.signTransaction(unSignedTransaction);
// broadcast the transaction
await tronWeb.trx.sendRawTransaction(signedTransaction);Documentation
API
Constructor(config: BinanceWalletAdapterConfig)
interface BinanceWalletAdapterConfig {
/**
* Set if open Wallet's website when wallet is not installed.
* Default is true.
*/
openUrlWhenWalletNotFound?: boolean;
/**
* Timeout in millisecond for checking if Binance wallet is supported.
* Default is 2 * 1000ms
*/
checkTimeout?: number;
/**
* Set if use WalletConnect as fallback when Binance Wallet is not found.
* Default is false.
*/
useWalletConnectWhenWalletNotFound?: boolean;
/**
* WalletConnect configuration, required when useWalletConnectWhenWalletNotFound is true.
*/
walletConnectConfig?: WalletConnectAdapterConfig;
/**
* Callback to receive the WalletConnect URI for custom QR code rendering.
* When provided, the AppKit modal will be skipped.
* Only used when falling back to WalletConnect.
*/
onWalletConnectUri?: (uri: string) => void;
}Example with WalletConnect fallback:
import { BinanceWalletAdapter } from '@tronweb3/tronwallet-adapter-binance';
const adapter = new BinanceWalletAdapter({
useWalletConnectWhenWalletNotFound: true,
walletConnectConfig: {
network: 'Nile',
options: {
projectId: 'your_project_id',
metadata: {
name: 'Your DApp',
description: 'Your DApp Description',
url: 'https://your-dapp.com',
icons: ['https://your-dapp.com/icon.png'],
},
},
},
// Optional: custom QR code rendering
onWalletConnectUri: (uri) => {
console.log('WalletConnect URI:', uri);
// Display your custom QR code here
},
});setOnWalletConnectUri(callback: ((uri: string) => void) | undefined): voidSet the onWalletConnectUri callback for custom QR code rendering. This allows dynamic configuration of the URI handler after adapter initialization.
adapter.setOnWalletConnectUri((uri) => { console.log('WalletConnect URI:', uri); // Display your custom QR code here });network()method is supported to get current network information. The type of returned value isNetworkas follows:export enum NetworkType { Mainnet = 'Mainnet', Shasta = 'Shasta', Nile = 'Nile', /** * When use custom node */ Unknown = 'Unknown', } export type Network = { networkType: NetworkType; chainId: string; fullNode: string; solidityNode: string; eventServer: string; };
Caveats
- Binance Wallet App doesn't implement
multiSign()andswitchChain(). - Binance Wallet App supports the following events:
connectdisconnectaccountsChanged
For more information about tronwallet adapters, please refer to @tronweb3/tronwallet-adapters
