npm i @toruslabs/torus-embed
import Torus from "@toruslabs/torus-embed";import Web3 from "web3";​const torus = new Torus();await torus.init();await torus.login(); // await torus.ethereum.enable()const web3 = new Web3(torus.provider);
import Torus from "@toruslabs/torus-embed";import Web3 from "web3";​const torus = new Torus({buttonPosition: "top-left" // default: bottom-left});await torus.init({buildEnv: "production", // default: productionenableLogging: true, // default: falsenetwork: {host: "kovan", // default: mainnetchainId: 42, // default: 1networkName: "Kovan Test Network" // default: Main Ethereum Network},showTorusButton: false // default: true});await torus.login(); // await torus.ethereum.enable()const web3 = new Web3(torus.provider);
The code snippet below sets Torus Wallet as the default login method for the DApp, paste the following script to the <body> of index.html.
<script src="https://cdn.jsdelivr.net/npm/@toruslabs/torus-embed"></script>
<script src="https://unpkg.com/@toruslabs/torus-embed"></script>
The script tag creates a window.torus
object. You can initialize it and use it as above.
You can also choose in load the embed via IPFS
<script src="https://ipfs.io/ipfs/QmVrWpAivFzEN6GGerdURNXfssr5YpHjTtZopHHGQ6AHmU"></script>
Please refer to the examples folder for sample implementations or the Class documentation for further init options.
Integrating with the Torus Wallet gives you a provider, which can be wrapped by the Web3. This instance functions similar to that as Metamask's web3 provider, and we have taken great care to make it compatible with Metamask's Web3 APIs.
If you are developing with the Torus Wallet in a local environment/with ganache, https is necessary to interact with app.tor.us. Check out the steps here to get started.
In general, the Torus wallet integration only works in a secure browser environment, as it needs access to browser APIs like window.open and window.crypto.