Skip to main content

Integrate via#

npm package#

npm i --save @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);

Script tag#

The code snippet below sets Torus Wallet as the default login method for a DApp, add one of the following script tags to end of body in your index.html.

<script src="https://cdn.jsdelivr.net/npm/@toruslabs/torus-embed"></script>

The script tag creates a window.torus object, which you can initialize and use as described above.

IPFS#

You may also choose to load the embed via IPFS:

<script src="https://ipfs.io/ipfs/QmVrWpAivFzEN6GGerdURNXfssr5YpHjTtZopHHGQ6AHmU"></script>

Examples#

Please refer to our examples for sample implementations or see API reference for more detailed usage options.

Web3/ether.js#

Integrating with the Torus Wallet gives you a provider, which can be wrapped by the Web3. This instance functions similar to Metamask's Web3 provider and we have taken great care to make it compatible with Metamask's Web3 APIs.

Development Environment#

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 steps 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.