Skip to content

Demo code

The following page presents a minimal piece of code for creating an account on Solide Network, and subsequently retrieving information on it.

First, setup a .env file in this directory with the following variables (Client id and secret will be securely shared to you by SolideFinance administrators.)

Terminal window
CLIENT_ID=<contact-support>
CLIENT_SECRET=<contact-support>
SOLIDE_FINANCE_API_URL=https://api-dev.solide.fi

The urls to SolideFinance and Auth0 apis are hard coded for simplicity sake.

Then, with node/npm installed, simply:

Terminal window
npm install axios dotenv

Some helper functions will be defined in their own JS module file, helpers.mjs for later use:

import axios from "axios";
import "dotenv/config";
export async function getSolideNetworkClient() {
// Initialize a SolideNetwork REST client pointing to the dev api
return axios.create({
baseURL: `https://api-dev.solide.fi/`,
headers: {
Authorization: `Bearer ${await getToken()}`,
/*
* Recommended - configure your auditing trail by setting `X-Operator-Id`
*/
// "X-Operator-Id": "my_end_user_id"
}
});
}
async function getToken() {
// Make sure to setup a .env with client_id and client_secret
const { data } = await axios.post(
"https://api-dev.solide.fi/oauth/token",
{
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET
},
{
headers: {
"Content-Type": "application/json"
}
}
);
const { access_token } = data;
return access_token;
}

With the .env variables properly set and the helper functions defined, you can create a simple script that will create a new account on Solide Network. You can choose any account id you want. We chose here demo-account-1:

import { getSolideNetworkClient } from "./helpers.mjs";
// The created account will have its own unique identifier, but I can specify my own identifier as well so I can match
// the account with an account in my systems
// The custom account id in my systems will be `demo-account-1`
const EXTERNAL_ACCOUNT_ID = "demo-account-1";
const solideNetworkClient = await getSolideNetworkClient();
try {
const { data: newAccountInfo } = await solideNetworkClient.post("accounts", {
externalId: EXTERNAL_ACCOUNT_ID,
});
console.log(newAccountInfo);
} catch (e) {
console.error(e.response.data);
}

Now, any subsequent operation this account that will affect the account balances can be monitored by calling the following script that fetches account info:

import { getSolideNetworkClient } from "./helpers.mjs";
const EXTERNAL_ACCOUNT_ID = "demo-account-1";
const solideNetworkClient = await getSolideNetworkClient();
const { data: account } = await solideNetworkClient.get(`accounts/externalId/${EXTERNAL_ACCOUNT_ID}`);
const { data: balances } = await solideNetworkClient.get(`accounts/externalId/${EXTERNAL_ACCOUNT_ID}/balances`);
console.log("Account balances:", account, balances);