2017-11-12 19:45:52 +00:00
|
|
|
import BN from 'bn.js';
|
2017-08-23 06:57:18 +00:00
|
|
|
import { toChecksumAddress } from 'ethereumjs-util';
|
2017-09-25 02:06:28 +00:00
|
|
|
import Contract, { ABI } from 'libs/contract';
|
2017-08-23 06:57:18 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Transfer {
|
|
|
|
to: string;
|
2017-11-12 19:45:52 +00:00
|
|
|
value: BN;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
2017-08-08 03:45:08 +00:00
|
|
|
|
|
|
|
const erc20Abi: ABI = [
|
|
|
|
{
|
|
|
|
constant: true,
|
|
|
|
inputs: [
|
|
|
|
{
|
|
|
|
name: '_owner',
|
|
|
|
type: 'address'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
name: 'balanceOf',
|
|
|
|
outputs: [
|
|
|
|
{
|
|
|
|
name: 'balance',
|
|
|
|
type: 'uint256'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
payable: false,
|
|
|
|
type: 'function'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
constant: false,
|
|
|
|
inputs: [
|
|
|
|
{
|
|
|
|
name: '_to',
|
|
|
|
type: 'address'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '_value',
|
|
|
|
type: 'uint256'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
name: 'transfer',
|
|
|
|
outputs: [
|
|
|
|
{
|
|
|
|
name: 'success',
|
|
|
|
type: 'bool'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
payable: false,
|
|
|
|
type: 'function'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
class ERC20 extends Contract {
|
|
|
|
constructor() {
|
|
|
|
super(erc20Abi);
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public balanceOf(address: string): string {
|
2017-08-08 03:45:08 +00:00
|
|
|
return this.call('balanceOf', [address]);
|
|
|
|
}
|
|
|
|
|
2017-11-12 19:45:52 +00:00
|
|
|
public transfer(to: string, value: BN): string {
|
2017-08-23 06:57:18 +00:00
|
|
|
return this.call('transfer', [to, value.toString()]);
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public $transfer(data: string): Transfer {
|
2017-08-23 06:57:18 +00:00
|
|
|
const decodedArgs = this.decodeArgs(this.getMethodAbi('transfer'), data);
|
|
|
|
return {
|
|
|
|
to: toChecksumAddress(`0x${decodedArgs[0].toString(16)}`),
|
2017-11-12 19:45:52 +00:00
|
|
|
value: decodedArgs[1]
|
2017-08-23 06:57:18 +00:00
|
|
|
};
|
2017-08-08 03:45:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new ERC20();
|