Single-Collateral Sai

Quick example

The code below creates a CDP, locks ETH into it, and draws out Sai.

import Maker from '@makerdao/dai';
async function openLockDraw() {
const maker = await Maker.create("http", {
privateKey: YOUR_PRIVATE_KEY,
url: 'https://kovan.infura.io/v3/YOUR_INFURA_PROJECT_ID'
});
await maker.authenticate();
const cdp = await maker.openCdp();
await cdp.lockEth(0.25);
await cdp.drawDai(50);
const debt = await cdp.getDebtValue();
console.log(debt.toString); // '50.00 DAI'
}
openLockDraw();

The services and objects below are used to work with Single-Collateral Sai.

openCdp()

  • Returns: promise (resolves to new CDP object once mined)

maker.openCdp() will create a new CDP, and then return the CDP object, which can be used to access other CDP functionality. The promise will resolve when the transaction is mined.

const newCdp = await maker.openCdp();

getCdp(int id)

  • Returns: promise (resolves to CDP object)

maker.getCdp(id) creates a CDP object for an existing CDP. The CDP object can then be used to interact with your CDP.

const cdp = await maker.getCdp(614);

Once you have an instance of a CDP, you can use CDP instance methods to read its state and perform actions.