To ensure an efficient implementation process, we highly encourage you to configure the environment to the requirements below :
NodeJS: 10.x
Integrating Torus with your DApp is as seamless as using it. Let us start by first installing Torus onto your DApp website.
You can install via a npm package.
Basic:
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);
Advanced:
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);
Please refer to the examples folder for sample implementations
Integrating with Torus gives you a provider, which can be wrapped by the Web3. This instance can be used to play with, read more on Web3's Documentation. You can implement web3 functionalities just like you would with Metamask.
Please include the following NPM packages:
process, buffer
And add the following code into polyfills.ts.
import * as process from 'process';window['process'] = process;(window as any).global = window;(window as any).global.Buffer = (window as any).global.Buffer || require('buffer').Buffer;
The code snippet below sets Torus as the default login method for the DApp, paste the following script to the <body> of index.html.