0.12.0-alpha • Published 7 years ago

@endpass/connect v0.12.0-alpha

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Endpass Connect

Compatible with web3.js@0.37.0beta and below

Table of contents

Library

Install library via npm of yarn.

npm i --save @endpass/connect
yarn add @endpass/connect

You don't need any dependencies like web3, Endpass Connect includes it out of the box.

Usage

Create instance of class and use it in your application. You can know about options and methods in the API section.

import Web3 from 'web3';
import EndpassConnect from '@endpass/connect';

const web3 = new Web3('https://network.url');
const connect = new EndpassConnect({
  appUrl: 'http://connect.url',
});
const provider = connect.extendProvider(web3);

web3.setProvider(provider);

Next, you can try to authentificate user.

try {
  const res = await connect.auth();

  // Now, you have active account address and network id
} catch (err) {
  // Something goes wrong! User is not authorized
}

Provider creating

If you want to use this library and process web3 requests through endpass services you should complete these conditions.

Install web3 library if you want to use it manually in you application. Create instance of web3 and create provider based on it:

import { HttpProvider } from 'web3-providers';
import Connect from '@endpass/connect';

const web3 = new Web3('https://network.url');
const connect = new Connect();
const provider = connect.extendProvider(HttpProvider);

// If you are using old versions of web3 (0.30.0-beta and below) you should call
// setProvider
web3.setProvider(provider);

// If you are using new versions of web3 (1.0.0 and more) you can reassign
// global property ethereum in application window object
window.ethereum = provider;

// We highly recommend to use both methods for more stability and compatibility
window.ethereum = provider;
web3.setProvider(provider);

If web3 can be found in application window object you can not install web3 manually, extendProvider also should try to find it.

API

Instance options

PropertyTypeDefaultDescription
authUrlstringhttps://auth.endpass.comUrl of Endpass Connect application.

Instance methods

MethodParamsReturnsDescription
authPromise<{ status: boolean, message?: string }>Open Endpass Connect application for user authorization, return promise, which returns object with auth status. See Errors handling for more details.
logoutPromise<Boolean>Makes logout request and returns status or throw error
getAccountDataPromise<{ activeAccount: string, activeNet: number }>Returns authorized user active account.
extendProviderprovider: Web3.ProviderWeb3ProviderCreates Web3 provider for injection in Web3 instance.
setProviderSettings{ activeAccount: string, activeNet: number }Set user settings to the injected web3 provider.
openAccountPromise<{ type: string, payload?: { activeAccount: string, activeNet: number } }>Open Endpass Connect application for change user active address, network or logout

Interactions with current account

If you use openAccount method connect application will open screen with user base settings: current account and network. You also can makes logout here. This method will return object with type field. This field determines response type. There is two types of response:

  • logout – means user makes logout from his account.
  • update – means user update account settings. Response also contains payload field with updated settings object.

At the same time update will set new account settings to injected provider. After this, you can refresh browser page or something else.

Examples:

import Connect from '@endpass/connect';

const connect = new Connect();

connect.openAccount().then(res => {
  if (res.type === 'logout') {
    // User have logout here
  } else if (res.type === 'update') {
    // Account settings was updated by user
    console.log(res); // { activeAccount: "0x0", activeNet: 1 }
  }
});

Development

CommandDescription
buildBuilds application and library.
dev:appStarts application dev server.
build:appBuilds application.
dev:libStarts library development environment.
build:libBuilds library.
test:unitRuns unit tests.
formatFormats code of packages with eslint and prettier.
0.33.3-beta

6 years ago

0.33.4-beta

6 years ago

0.33.2-beta

6 years ago

0.33.0-beta

6 years ago

0.32.0-beta

6 years ago

0.31.4-beta

6 years ago

0.31.3-beta

6 years ago

0.31.1-beta

6 years ago

0.31.0-beta

6 years ago

0.30.1-beta

6 years ago

0.30.0-beta

6 years ago

0.29.6-beta

6 years ago

0.29.5-beta

6 years ago

0.29.4-beta

6 years ago

0.29.3-beta

6 years ago

0.29.2-beta

6 years ago

0.29.1-beta

6 years ago

0.29.0-beta

6 years ago

0.28.14-beta

6 years ago

0.28.13-beta

6 years ago

0.28.12-beta

6 years ago

0.28.11-beta

6 years ago

0.28.10-beta

6 years ago

0.28.9-beta

6 years ago

0.28.8-beta

6 years ago

0.28.7-beta

6 years ago

0.28.6-beta

6 years ago

0.28.4-beta

6 years ago

0.28.3-beta

6 years ago

0.28.2-beta

6 years ago

0.28.0-beta

6 years ago

0.27.3-beta

6 years ago

0.27.2-beta

6 years ago

0.27.1-beta

6 years ago

0.27.0-beta

6 years ago

0.26.3-beta

7 years ago

0.26.2-beta

7 years ago

0.26.1-beta

7 years ago

0.26.0-beta

7 years ago

0.25.1-beta

7 years ago

0.25.0-beta

7 years ago

0.24.3-beta

7 years ago

0.24.2-beta

7 years ago

0.24.1-beta

7 years ago

0.24.0-beta

7 years ago

0.23.3-beta

7 years ago

0.23.2-beta

7 years ago

0.23.1-beta

7 years ago

0.22.3-beta

7 years ago

0.23.0-beta

7 years ago

0.22.1-beta

7 years ago

0.22.0-beta

7 years ago

0.21.4-beta

7 years ago

0.21.3-beta

7 years ago

0.21.2-beta

7 years ago

0.21.1-beta

7 years ago

0.20.2-beta

7 years ago

0.20.1-beta

7 years ago

0.20.0-beta

7 years ago

0.19.5-beta

7 years ago

0.19.4-beta

7 years ago

0.19.3-beta

7 years ago

0.19.2-beta

7 years ago

0.19.1-beta

7 years ago

0.19.0-beta

7 years ago

0.18.0-beta

7 years ago

0.17.7-beta

7 years ago

0.17.6-beta

7 years ago

0.17.5-beta

7 years ago

0.17.4-beta

7 years ago

0.17.3-beta

7 years ago

0.16.1-beta

7 years ago

0.16.0-beta

7 years ago

0.15.8-beta

7 years ago

0.15.7-beta

7 years ago

0.15.6-beta

7 years ago

0.15.5-beta

7 years ago

0.15.4-beta

7 years ago

0.15.3-beta

7 years ago

0.15.2-beta

7 years ago

0.15.1-beta

7 years ago

0.15.0-beta

7 years ago

0.14.0-beta

7 years ago

0.13.1-beta

7 years ago

0.13.0-beta

7 years ago

0.12.4-beta

7 years ago

0.12.3-beta

7 years ago

0.12.2-beta

7 years ago

0.12.1-beta

7 years ago

0.12.0-alpha

7 years ago

0.11.2-alpha

7 years ago

0.10.2-alpha

7 years ago

0.10.1-alpha

7 years ago

0.10.0-alpha

7 years ago

0.9.0-alpha

7 years ago

0.8.0-alpha

7 years ago

0.7.0-alpha

7 years ago

0.6.4-alpha

7 years ago

0.6.3-alpha

7 years ago

0.6.2-alpha

7 years ago

0.6.1-alpha

7 years ago

0.6.0-alpha

7 years ago

0.5.3-alpha

7 years ago

0.5.2-alpha

7 years ago

0.5.1-alpha

7 years ago

0.5.0-alpha

7 years ago

0.4.0-alpha

7 years ago

0.3.0-alpha

7 years ago

0.2.3-alpha

7 years ago

0.2.2-alpha

7 years ago

0.2.1-alpha

7 years ago

0.2.0-alpha

7 years ago