Quick Start
Example Code
// 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 }
})).dataLast updated