Tokens
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 ownerspender- address of token spenderReturns: promise (resolves to token allowance)
allowance returns a currency unit representing the token allowance.
balance
Params: none
Returns: promise (resolves balance of current account)
balance returns a currency unit representing the token balance of the current account
balanceOf
Params: address to check
Returns: promise (resolves balance of address)
balanceOf returns a currency unit representing the token balance of the supplied account.
totalSupply
Params: none
Returns: promise (resolves total supply of token)
totalSupply returns a currency unit representing the total token supply
approve
Params:
spender - address of token spender
amount - amount of token to allow
Returns: promise (resolves to transactionObject once mined)
approve approves the spending address to spend up to amount of msg.sender's tokens.
approveUnlimited
Params: address of token spender
Returns: promise (resolves to transactionObject once mined)
approveUnlimited approves the spending address to spend the maximum amount of msg.sender's tokens.
transfer
Params:
to - address to send to
amount - amount of token to send
Returns: promise (resolves to transactionObject once mined)
transfer transfers amount of token to to address.
transferFrom
Params:
from - address to send tokens from
to - address to send to
amount - amount of token to send
Returns: promise (resolves to transactionObject once mined)
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)
Params: amount of Eth to deposit
Returns: promise (resolves to transactionObject once mined)
deposit converts amount of Eth to amount of Weth.
withdraw (WETH only)
Params: amount of Weth to withdraw
Returns: promise (resolves to transactionObject once mined)
withdraw converts amount of Weth to amount of Eth.
join (PETH only)
Params: amount of Weth to join
Returns: promise (resolves to transactionObject once mined)
join converts amount of Weth to Peth, at the Weth to Peth Ratio.
exit (PETH only)
Params: amount of Peth to exit
Returns: promise (resolves to transactionObject once mined)
withdraw converts amount of Peth to Weth, at the Weth to Peth Ratio.
Last updated