Getting started

Installation

Install the package with npm in your terminal:

npm install @makerdao/dai

Once it's installed, import the module into your project as shown below.

import Maker from '@makerdao/dai';
// or
const Maker = require('@makerdao/dai');

Multi-Collateral Dai support in Dai.js is implemented as a plugin. This may change in the future. The MCD Plugin is also available as an npm package and its source code can be found on Github.

npm install @makerdao/dai-plugin-mcd

import { McdPlugin } from '@makerdao/dai-plugin-mcd';
// or
const { McdPlugin } = require('@makerdao/dai-plugin-mcd');

(Note the .default at the end of the line when using require.)

UMD

This library is also usable as a UMD module, which you can build with npm run build:frontend.

<script src="./dai.js" />

<script>
// once the script loads, window.Maker is available
</script>

Quick Examples

Look up information about a vault

This code uses getCdpIds to look up a vault that was created in the Oasis Borrow UI. Since this code is only reading data, not creating any transactions, it is not necessary to provide a private key or connect a wallet.

Create a vault

The code below opens a Vault, locks ETH into it, and draws out Dai.

Since this code sends transactions, it requires an account that can sign transactions. The simplest way to do this is to provide a privateKey configuration option as shown below, but you can also connect to Metamask or other browser-based providers, or connect to hardware wallets.

In the next section, learn more about how to configure the Maker instance with Maker.create. Or jump to learning more about accounts, vaults, proxies, and currency units.

Integration Examples

For larger examples of integrating this library, check out this repo and the Dai react template.

Last updated