Skip to content
Branch: master
Find file Copy path
Find file Copy path
3 contributors

Users who have contributed to this file

@vamsiraju @pcatana @lassebirk
146 lines (74 sloc) 9.58 KB

Dai Token

Level: Beginner

Estimated Time: 30 - 60 minutes


Dai is a decentralized stablecoin currently live on the Ethereum network. The Maker Protocol incentivizes users to increase or decrease the Dai token supply based on supply and demand and ensures its value stays pegged to 1 USD.

The token contract conforms to the ERC20 token standard which allows wallets, exchanges, and other applications to easily integrate with minimal effort. This guide will be useful to developers integrating Dai in applications like wallets, exchanges, and smart contracts to get a better understanding of the token contract and its functionality.

Learning Objectives

  • You will learn basic information about the token.

  • Understand the additional functions supported by the token contract.

  • Deploy your own token to an Ethereum testnet.

  • Integrate the Dai token effectively with your application.


  • Knowledge of the ERC20 token standard.

  • Ability to send ethereum transactions from your preferred dev environment.


Token Info


Dai is available on the Ethereum mainnet at 0x6b175474e89094c44da98b954eedeac495271d0f and the Kovan testnet at 0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa.


The symbol field is set to ‘DAI’ and the name field is currently set to ‘Dai Stablecoin’.

Token precision field decimals is set to 18 like most other ERC20 tokens.

Token stats

Multi Collateral Dai has been live on the Ethereum mainnet since November 18, 2019 and its current total supply can be viewed on DaiStats.

Sai (legacy Dai) has been live on the Ethereum mainnet since December 17, 2017 and its current total supply can be viewed on MakerScan. Supply varies constantly as new tokens are generated or removed every time a user creates new debt or pays their existing debt off on their Collateralized Debt Position(CDP). You can also see additional stats of the token updated real-time on Note that MakerScan or are websites maintained by the community and may not always produce accurate data.

The system internally uses 1 USD as the target price of Dai when it issues new debt or removes existing debt from a Vault but the market price of the token could vary based on a variety of conditions like exchange liquidity, trading pair etc.

Care should be taken before using the price of Dai directly reported by sources like CoinMarketCap, because exchange bugs may produce unreasonable price data. In many scenarios, such as displaying the value of Dai in a wallet, it is perfectly fine to hard code the price of a token to 1 USD.

Getting Dai


Dai can be purchased with Ether on many popular exchanges, It is also available on many decentralized exchanges like Oasis, KyberSwap, and Uniswap.

You can also create your own Dai by opening a Vault with


The best method to get Kovan Dai is to open a testnet Vault using Kovan ETH and create your required amount of Dai from it. The lowest collateralization ratio will give you the most bang for the buck! Another option is to buy Kovan Dai with Kovan ETH on [Oasis]( if there is sufficient liquidity available.

Token Contract


Dai token is deployed using the DSToken codebase from Dappsys. It implements all functions and events as defined in the ERC20 token standard. The codebase at commit f22f681 was used for deployments on both networks.

Binary approval can be given to addresses by token holders using approve(address) which sets the approved token amount to MAX_UINT.

DSToken implements additional mint and burn functions to increase/decrease the total token supply under certain conditions. Permission checks are delegated to an authority contract which checks whether the caller is authorized to execute these protected functions or not.

Tokens are created when a user adds collateral to their Vault and creates new Dai from it. Tokens are destroyed when the same user pays back the same amount of Dai they’ve previously issued for the system to remove them from the supply and return their locked collateral back.

The MCD_DAI_JOIN adapter contract in the Maker Protocol process calls to the Dai token which can increase or decrease the total supply.


Mint has the function signature: mint(address guy, uint wad). It increases the total supply of the token as well as the guy’s token balance by the wad amount. This generates an event with the signature: Mint(address indexed guy, uint wad). All calls to mint() originate from the exit() function on the DaiJoin contract.


Burn has the function signature: burn(address guy, uint wad). It decreases the total supply of the token as well as the guy’s token balance by the wad amount. It also generates an event with the signature: Burn(address indexed guy, uint wad).

Calls to burn() originate from join() function on the DaiJoin contract.


Owner variable in the contract has been set to the 0x0 address after deployment. Token holder functions like transferFrom(), and approve() are fully open for existing token holders to call.

Emergency Shutdown

MKR holders through their governance contract can vote to shut down the system by executing the cage() function on the ESM contract.

After emergency shutdown, all DAI holders are allowed to claim collateral for each token at the last price reported by price feed oracles. Two functions- cash() and pack(), are activated in END contract. Cash() allows token holders to redeem Dai for ETH at the exchange ratio set at emergency shutdown.

The transferFrom() function has a few aliases available: push, pull, and move, both mint and burn functions also have aliases that automatically create or remove Dai of the msg.sender.

Deploy a DSToken

You will need to install dapptools to finish this section. Installation instructions can be found here, Initialize your .sethrc file with the right values for the env variables SETH_CHAIN and ETH_FROM as mentioned here. Seth will automatically search the default folder paths for Geth and Parity keystores, or your Ledger hardware wallet, for the address you've set.

Clone a local copy of the DSToken repo from this link,

Run dapp update to initialize all the git submodules present in the repo. Run dapp build to build the codebase and generate the files required to deploy the token contract.

Run dapp create DSTokenFactory to deploy the DSTokenFactory contract, which we'll use to deploy a new token contract next. Copy the address of the factory to use in our next command.

Use seth to call make() on the factory contract with symbol and name as input to deploy a new DSToken. Bytes32 values in the following command will set the symbol to 'DAI' and name to 'Dai Stablecoin v1.0' on the deployed token contract.

seth send DSTokenFactoryAddress 'make(bytes32,bytes32)' 0x4441490000000000000000000000000000000000000000000000000000000000 0x44616920537461626c65636f696e2076312e3000000000000000000000000000

This command will deploy a new DSToken with your address set as the owner.


In this guide, we briefly discussed the technical details of the Dai token contract as well as a quick summary of its role in the Dai Credit System. Please refer to the links embedded in the document as well as the additional resources section for more information. We also urge you to explore the various tools and services built on top of Dai by our partner ecosystem.

Additional resources


  2. Using Dai in smart contracts




You can’t perform that action at this time.