GuidesAPI ReferenceCommunity
GuidesCommunityLog In

Javascript SDK

The official SDK is used to access the Bitcapital Core services in JS and TS environments. It resided in the NPM Registry as an Open Source project.

Getting Started

Install as a project dependency using Yarn, remember to specify the desired version.

# Install using Yarn (recommended)
yarn add "@bitcapital/core-sdk";

# Install using NPM
npm install "@bitcapital/core-sdk";

Setting up your client

To start using this SDK you need both a Client ID and a Client Secret, emitted by the Bitcapital Core Team and the URL for the instance you're going to operate over. Every instance has its unique URL and previously authorized OAuth Clients.

If you don't have yours yet, checkout the guide on Requesting your credentials.

import Bitcapital, { User } from '@bitcapital/core-sdk';

// Initialize the session instance to authenticate
// using the Bitcapital Core OAuth 2.0 provider.
const bitcapital = Bitcapital.initialize({
  // Instance URL for REST API calls
  baseURL: '',
  // Credentials for OAuth 2.0 requests
  clientId: '< YOUR CLIENT_ID HERE >',
  clientSecret: '< YOUR CLIENT_SECRET HERE >',

try {
  // Authenticate a user with email and password from Bitcapital Core
  // If succeeds and available, the credentials will be stored in the 
  // session instance and in the local storage (for browser environments).
  const user: User = await bitcapital.session().password({
    username: '[email protected]',
    password: '12345678',

  // The session returns the user info and credentials
} catch(exception) {
  // Something went wront, probably credentials are invalid

To destroy the current credentials for disposal of the client instance, use the session.destroy() method.

// This will trigger a session clean up
// All session subscribers will be notified asynchronously
await bitcapital.session().destroy();

What’s Next
Did this page help you?