Maker Protocol Technical Docs
  • MakerDAO Technical Docs
  • Getting Started
    • Maker Protocol 101
  • Smart Contract Modules
    • Dai Module
      • Dai - Detailed Documentation
    • Core Module
      • Vat - Detailed Documentation
      • Spot - Detailed Documentation
    • Collateral Module
      • Join - Detailed Documentation
    • Liquidation 2.0 Module
    • System Stabilizer Module
      • Flapper - Detailed Documentation
      • Flopper - Detailed Documentation
      • Vow - Detailed Documentation
    • Oracle Module
      • Oracle Security Module (OSM) - Detailed Documentation
      • Median - Detailed Documentation
    • MKR Module
    • Governance Module
      • Spell - Detailed Documentation
      • Pause - Detailed Documentation
      • Chief - Detailed Documentation
    • Rates Module
      • Pot - Detailed Documentation
      • Jug - Detailed Documentation
    • Proxy Module
      • Proxy Actions - Detailed Documentation
      • Vote Proxy - Detailed Documentation
      • CDP Manager - Detailed Documentation
      • DSR Manager - Detailed Documentation
    • Flash Mint Module
    • Maker Protocol Emergency Shutdown
      • Emergency Shutdown for Partners
      • The Emergency Shutdown Process for Multi-Collateral Dai (MCD)
      • End - Detailed Documentation
      • ESM - Detailed Documentation
  • Glossary
    • MCD Glossaries
    • Smart Contract Annotations
  • Deployment Addresses
    • Maker Protocol Deployments
  • Security
    • Security for the Maker Protocol
  • Building on top of the Maker Protocol
    • Developer Guides and Tutorials
    • The Dai Javascript Library of the Maker Protocol
      • Getting started
      • Configuration
        • Plugins
      • Vault manager
      • Collateral types
      • Dai Savings Rate
      • Currency units
      • System data
      • Advanced
        • Transaction manager
        • DSProxy
        • Events
        • Using multiple accounts
        • Adding a new service
      • Single-Collateral Sai
        • Collateralized Debt Position
        • CDP Service
        • Price Service
        • System Status
        • Tokens
        • Token Conversion
        • Exchange Service
    • Pymaker
  • Keepers
    • The Auctions of the Maker Protocol
    • Auction Keepers
      • Auction Keeper Bot Setup Guide
    • Market Maker Keepers
      • Market Maker Keeper Bot Setup Guide
    • Cage Keeper
    • Simple Arbitrage Keeper
    • Chief Keeper
  • Command-line Interfaces
    • Seth
    • Multi Collateral Dai (MCD) CLI
    • Dai and Collateral Redemption during Emergency Shutdown
    • Emergency Shutdown (ES) CLI
  • Miscellaneous
    • Liquidations 1.2 System (Deprecated)
      • Cat - Detailed Documentation
      • Flipper - Detailed Documentation
    • SCD <> MCD Migration
    • Upgrading to Multi-Collateral Dai Guide
Powered by GitBook
On this page
  • allowance
  • balance
  • balanceOf
  • totalSupply
  • approve
  • approveUnlimited
  • transfer
  • transferFrom
  • deposit (WETH only)
  • withdraw (WETH only)
  • join (PETH only)
  • exit (PETH only)
Export as PDF
  1. Building on top of the Maker Protocol
  2. The Dai Javascript Library of the Maker Protocol
  3. Single-Collateral Sai

Tokens

PreviousSystem StatusNextToken Conversion

Last updated 4 years ago

Get a token object through the getToken(tokenSymbol) function on the tokenService.

The list of tokens that can be passed into getToken() are: SAI, MKR, WETH, PETH, ETH.

This list can also be obtained with tokenService.getTokens(). This function returns a string representation of the token symbol, e.g. 'SAI', which can also be passed into getToken.

When the Multi-Collateral Dai plugin is in use, getToken('DAI') will return a token object for Dai.

const tokenService = maker.service('token');
const sai = tokenService.getToken('SAI');
const weth = tokenService.getToken('WETH');
const peth = tokenService.getToken('PETH');

Most of the methods below can be called on any token object. deposit and withdraw are for WETH only, and join and exit are for PETH only.

allowance

const allowance = await dai.allowance('0x...owner', '0x...spender');
  • Params:

  • tokenOwner - address of token owner

  • spender - address of token spender

  • Returns: promise (resolves to token allowance)

allowance returns a representing the token allowance.

balance

const balance = await dai.balance();
  • Params: none

  • Returns: promise (resolves balance of current account)

balanceOf

const balanceOf = await dai.balanceOf('0x...f00');
  • Params: address to check

  • Returns: promise (resolves balance of address)

totalSupply

const totalSupply = await dai.totalSupply();
  • Params: none

  • Returns: promise (resolves total supply of token)

approve

return await dai.approve('0x...f00', DAI(10));
  • Params:

  • spender - address of token spender

  • amount - amount of token to allow

approve approves the spending address to spend up to amount of msg.sender's tokens.

approveUnlimited

return await dai.approveUnlimited('0x...f00');
  • Params: address of token spender

approveUnlimited approves the spending address to spend the maximum amount of msg.sender's tokens.

transfer

return await dai.transfer('0x...f00', DAI(10));
  • Params:

  • to - address to send to

  • amount - amount of token to send

transfer transfers amount of token to to address.

transferFrom

return await dai.transferFrom('0x...fr0m', '0x...t0', DAI(10));
  • Params:

  • from - address to send tokens from

  • to - address to send to

  • amount - amount of token to send

transferFrom() transfers amount of token from from address to to address. Transaction will fail if msg.sender does not have allowance to transfer the amount of tokens from the from address.

deposit (WETH only)

return await weth.deposit(ETH(10));
  • Params: amount of Eth to deposit

deposit converts amount of Eth to amount of Weth.

withdraw (WETH only)

return await weth.withdraw(WETH(10));
  • Params: amount of Weth to withdraw

withdraw converts amount of Weth to amount of Eth.

join (PETH only)

return await peth.join(WETH(10));
  • Params: amount of Weth to join

exit (PETH only)

return await peth.exit(PETH(10));
  • Params: amount of Peth to exit

balance returns a representing the token balance of the current account

balanceOf returns a representing the token balance of the supplied account.

totalSupply returns a representing the total token supply

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

join converts amount of Weth to Peth, at the .

Returns: promise (resolves to once mined)

withdraw converts amount of Peth to Weth, at the .

currency unit
currency unit
currency unit
currency unit
transactionObject
transactionObject
transactionObject
transactionObject
transactionObject
transactionObject
transactionObject
Weth to Peth Ratio
transactionObject
Weth to Peth Ratio