Skip to main content

Create a new project

Create a new directory and initialize a new npm package.
mkdir formance-js-example
cd formance-js-example
npm init -y
If using TypeScript, install the required dependencies:
  • TypeScript
Install TypeScript and the Node.js type definitions.
npm install --save-dev typescript @types/node ts-node
npx tsc --init

Install the Formance SDK

Install the Formance SDK and the Formance OAuth helper:
npm install --save @formance/formance-sdk
The Formance API relies on OAuth 2.0 for authentication. The Formance OAuth helper simplifies the OAuth flow and provides a simple interface to obtain an access token using the client_credentials grant type. For more information, see OAuth 2.0.
The Formance OAuth helper uses the client_credentials grant type, which requires a client ID and client secret. These are sensitive credentials and should not be exposed to the public. If you’re integrating Formance into a web application, you should use an OAuth flow that does not require a client secret, such as the authorization code grant.

Hello World from the Formance Ledger

Replace the values with your API endpoint and credentials from the Authentication & Credentials Setup guide.
  • TypeScript
  • JavaScript
Create a new file index.ts and add the following code:
import { SDK as Formance } from '@formance/formance-sdk';

const ENDPOINT = "https://xxxxxxxxxx-xxxx.sandbox.formance.cloud";

const formance = new Formance({
    serverURL: ENDPOINT,
    security: {
        clientID: "RANDOM_KEY",
        clientSecret: "RANDOM_KEY",
    }
});

async function main() {
    const ledgerInfo = await formance.ledger.getInfo();
    console.log(ledgerInfo.configInfoResponse!.data);
}

main();
Run the file using ts-node:
npx ts-node index.ts
Output:
{
  config: { storage: { driver: 'postgres', ledgers: [Array] } },
  server: 'numary-ledger',
  version: 'v1.10.13'
}
Numary was Formance’s former name.