ThetaPass for dapps - JavaScript


Looking for OAuth 2.0?

Check out the OAuth 2.0 docs:

Example Project

View on GitHub

Getting started

ThetaPass - slim library to interact with user's ThetaDrop managed wallets (read-only currently).

Installing ThetaPass

Dapps must use the ThetaPass library to interact (read-only) with the user's managed wallet on ThetaDrop to prove ownership of NFTs.

npm install --save @thetalabs/theta-pass


Three different ways to import depending on your project.

node.js require

const ThetaPass = require("@thetalabs/theta-pass");


import {ThetaPass} from '@thetalabs/theta-pass';

JS Script Tag

<script type="application/javascript" src="//[email protected]/dist/theta-pass.umd.js"></script>

Request user's managed wallet address on ThetaDrop

Via Popup

const RedirectUrl = 'http://localhost:8080/example/callback.html';
const response = await ThetaPass.requestAccounts(RedirectUrl, null, true);
const {request, result} = response;
const walletAddress = result[0];

Via Redirect

const RedirectUrl = 'http://localhost:8080';
await ThetaPass.requestAccounts(RedirectUrl, null, false);

You'll need to add some code to detect when the user is returning from the redirect.

// TODO: add error handling for when the user is not coming from a redirect
const response = await ThetaPass.getResponse();
const {request, result} = response;
const walletAddress = result[0];

Prove NFT ownership via Smart Contracts

Using theta.js

Fetch the account info for a connected user.

Learn more about Theta.js setup here:

const thetajs = require("@thetalabs/theta-js");

Check Balance of NFT Collection

const userWalletAddress = '0x0'; // From earlier ThetaPass requestAccounts result
const nftContractAddress = '0x1';
const nftABI = ThetaPass.THETA_DROP_NFT_ABI;
const provider = new thetajs.providers.HttpProvider();
const contract = new thetajs.Contract(nftContractAddress, nftABI, provider);
const balance = await contract.balanceOf(userWalletAddress);
// If balance > 0, user has at least one of these NFTs
if(balance.toNumber() > 0){
     // User owns at least 1 of this NFT!  (Unlock content, etc) 
     // User does not own this NFT