Quick Start

Use the Thallo SDK NPM library to integrate at lightning speed âš¡

Example Code

The full working code for this example can be found here.

In this example we do the following:

  1. Get the market data, this contains sell orders for specific projects and vintages, including quantity available and the price per tonne.

  2. Get the rich project data for all projects that have credits for sale.

  3. Find a project that has been implemented in Sierra Leone.

  4. Ensure the price is within your defined boundaries.

  5. Purchase 1 whole tonne and retire 20 grams of the credits in one atomic action.

The purchase will only be made if you do not have 20 grams for this project and vintage available in your CaaS inventory

// get market data
const marketData = (await httpClient.get('/api/market')).data
// get project ids so we can get the project details
const projectIds = marketData.projects.map((project: { project_id: string }) => project.project_id)

// we should cache the project data as it doesn't change often
const projects = (await httpClient.get('/api/projects', {
    params: { project_ids: projectIds }
})).data.projects

// select project from Sierra Leone
const selectedProject = projects.filter((project: { location: string }) => project.location === 'SL')[0]

// get sell order for this project
const vintage = marketData.projects.filter((project: { project_id: string }) => project.project_id === selectedProject.project_id)[0]
    .vintages[0]
const sellOrder = vintage.sell_orders[0]

// ensure the price is less than the max we're comfortable paying e.g. $10.45
if (BigNumber.from(sellOrder.price_cents).gt(1045)) {
    throw new Error('Sell order price too high')
}

// request retirement
const retirementRequestId = (await httpClient.post('api/caas/request-retirement', {
    quantity_grams: '20',
    vintage_id: vintage.vintage_id,
    sell_order_id: sellOrder.sell_order_id,
    expected_price_cents: sellOrder.price_cents,
})).data.retirement_request_id

// get retirement details
const retirement = (await httpClient.post('api/retirement', {
    params: { id: retirementRequestId }
})).data

Last updated