Using Torus to connect to common social networks

Metamask’s intimidating interface

An Online Wallet Without the Hassle

Torus is a project designed to make interacting with web3 DApps much slicker for the user. Instead of having to install a browser extension, and to keep a new password safe, you can log in using Facebook, Google, and a whole host of others. This brings logging into DApps into the 21st century.


Install in Four Simple Steps

For the full documentation, go to Torus’s website.

Step 1: Install packages

The torus package can be found on NPM and installed using the following command:

npm install @toruslabs/torus-embed
npm install web3

Step 2: Importing and requiring

In the file you wish to make the connection in, make sure you have the following code at the head of the file:

import Torus from "@toruslabs/torus-embed";
import Web3 from "web3";

Step 3: Initialize Torus

In the same file, we need to initialize the Torus object so that we can start interacting with it. To do this, copy the following into your file:

const torus = new Torus();
await torus.init();

Step 4: Login and initialize Web3

If you want your DApp to log the user in straightaway, paste these commands immediately below the previous lines. If you want the user to log on in the event of a button click, put these in the listener to that event.

await torus.login(); // await torus.ethereum.enable()
const web3 = new Web3(torus.provider);

Login example using Torus

LEAVE A REPLY

Please enter your comment!
Please enter your name here