diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-06-01 01:25:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-01 01:25:03 +0800 |
commit | 1c765cd55f227d99941f5944ff60022884890fe1 (patch) | |
tree | 246ed68ffad1036b5545e35f3123de3ec98801a4 /src/contract_wrappers | |
parent | 11b6b36ccaac04f39b425345daa61396a62ab0fc (diff) | |
parent | 4d43f4d6108575b889aca8e8c969574c121ce0c9 (diff) | |
download | dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.tar dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.tar.gz dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.tar.bz2 dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.tar.lz dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.tar.xz dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.tar.zst dexon-sol-tools-1c765cd55f227d99941f5944ff60022884890fe1.zip |
Merge pull request #28 from 0xProject/erc20transfer
Add transfer function and tests for it
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 35e008905..cedbfbdae 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -52,7 +52,7 @@ export class TokenWrapper extends ContractWrapper { * of an owner address. */ public async setProxyAllowanceAsync(tokenAddress: string, ownerAddress: string, - amountInBaseUnits: BigNumber.BigNumber) { + amountInBaseUnits: BigNumber.BigNumber): Promise<void> { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); @@ -69,6 +69,21 @@ export class TokenWrapper extends ContractWrapper { gas, }); } + /** + * Transfers `amountInBaseUnits` ERC20 tokens from `fromAddress` to `toAddress`. + */ + public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, + amountInBaseUnits: BigNumber.BigNumber): Promise<void> { + assert.isETHAddressHex('tokenAddress', tokenAddress); + assert.isETHAddressHex('fromAddress', fromAddress); + assert.isETHAddressHex('toAddress', toAddress); + assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); + + const tokenContract = await this.getTokenContractAsync(tokenAddress); + await tokenContract.transfer(toAddress, amountInBaseUnits, { + from: fromAddress, + }); + } private async getTokenContractAsync(tokenAddress: string): Promise<TokenContract> { let tokenContract = this.tokenContractsByAddress[tokenAddress]; if (!_.isUndefined(tokenContract)) { |