Skip to main content

Web

The Vezgo JS SDK opens Vezgo Connect inside any web app, so your users can connect their exchanges, wallets and blockchains. In the browser it needs only your client ID: it gets each user token from your backend, and never sees your client secret.

Install​

npm install vezgo-sdk-js
import Vezgo from 'vezgo-sdk-js';

Or load the browser build, which defines a global Vezgo. Pin a version: the unversioned URL always serves the latest, which can contain breaking changes.

<script src="https://unpkg.com/vezgo-sdk-js@2.0.8/dist/vezgo.umd.js"></script>

Initialize​

const vezgo = Vezgo.init({
clientId: 'YOUR_CLIENT_ID',
// An endpoint on your backend that returns { token } for the logged-in user (POST)
authEndpoint: '/vezgo/auth',
});

// No loginName in the browser: your backend knows who the user is
const user = vezgo.login();

Your backend's authEndpoint requests the token with your client secret: see Serve tokens to your frontend. To fetch the token yourself instead, pass an authorizer function. Both are described in Authentication.

Open Connect​

document.getElementById('connect').addEventListener('click', () => {
user
.connect()
.onConnection(async (accountId) => {
// Store the account ID with your user, on your backend
await sendToServer(accountId);
})
.onError((error) => console.error('Connection error:', error))
.onEvent((name, data) => console.log('Connect event:', name, data));
});

user.connect() opens the Connect widget over your page. To choose its providers, language or theme, or open it on one provider, see Integrate the widget and Customize your widget.

Read the data​

The same user reads the accounts it connected, for example to show them right away:

const account = await user.accounts.getOne(accountId);

Store account IDs on your backend and read the data from there, with the Node.js or Python SDK.