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.
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.
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.
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:
See api reference for more details.
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.
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.
To logout user which means to clean up the web3 instance ,it simply requires you to call
logout function on torus wallet instance
You can refer to api docs to explore more in to torus wallet apis here