Skip to main content

How to Integrate Torus Wallet and Binance Smart Chain


This tutorial will guide you over a basic example to integerate torus wallet with Binance Smart Chain.

We will go through a simple html page app where user can login in to torus wallet, connect over binance smart chain and can sign a transactions using torus wallet.

Let's get started with code by installing depedencies using npm

To start with using torus wallet with a binance smart chain dapp , you need to install torus-embed and web3. You can use popular package managers like yarn and npm to down them. In this guide we will load them over cdn script.

   <script src=""> <script>
<script src=""></script>

Initialize torus wallet with binance test net:

    const torus = new Torus({
buttonPosition: 'bottom-left', // customize position of torus icon in dapp

window.torus = torus
await torus.init(
enableLogging: true,
network: {
host: "", // mandatory
networkName: "Smart Chain - Testnet",
chainId: 97,
blockExplorer: "",
ticker: 'BNB',
tickerName: 'BNB',
showTorusButton: true,

In above code snippet, we are creating an instance of torus-embed and then initializing it with binance smart chain test node configuration. We can pass other configuration options while initializing for customizing torus wallet interface. You can refer to torus-embed api-reference to know more on that.

Trigger user login

Simply call torus.login to trigger user login wherever it makes sense in your application lifecycle:

Calling login without any parameter will open a modal for user to select all supported logins:

  await window.torus.login();

See api reference for more details.

Using torus web3 instance to fetch user account address and balance

After login with torus wallet it provides us with a http provider as torus.provider which can be feeded in to web3 js to interact with binance smart chain.

It also provides us with an interface to access user login information like user's email , profile image etc.

const user = await window.torus.getUserInfo(); // user profile info (email address etc)

const web3 = new Web3(window.torus.provider);
window.web3 = web3
const address = (await web3.eth.getAccounts())[0];
const balance = await web3.eth.getBalance(address);

Using torus web3 provider instance to sign transactions.

Now we have access to a web3 instance using which we can do anything from signing transactions to accessing other methods of web3.

Every time you will try to sign a transaction it will automatically open torus wallet window for user where user can confirm transaction.

 window.web3.eth.getAccounts((error, accounts) => {
if (error) throw error;
const txnParams = {
from: accounts[0],
to: accounts[0], // any valid receiver address
value: "0.1"
window.web3.eth.sendTransaction(txnParams, (error, txnHash) => {
if (error) throw error;

Log out handler

To logout user which means to clean up the web3 instance ,it simply requires you to call logout function on torus wallet instance

   await window.torus.logout()


You can refer to api docs to explore more in to torus wallet apis here