-
Notifications
You must be signed in to change notification settings - Fork 1
/
withdraw.js
executable file
·58 lines (54 loc) · 1.75 KB
/
withdraw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
const { ACCOUNT, TOKEN_CONTRACTS } = require('./constants')
const { transferToken } = require('./token/transfer-token')
const { getQuantity } = require('./utils')
const pressAnyKey = require('./node_modules/press-any-key')
var argv = require('yargs/yargs')(process.argv)
.command('Tranfer cryptocurrency from your account to another account')
.example(
'$0 -p 10000 -s foobar -r cryptotester -m "Hello!"',
'Send 10k FOOBAR to cryptotester with "Hello!" as memo.'
)
.describe('amount', 'Amount')
.alias('p', 'amount')
.describe('symbol', 'Symbol')
.alias('s', 'symbol')
.describe('receiver', 'Receiver')
.alias(['t', 'r'], 'receiver')
.describe('memo', 'Memo')
.alias('m', 'memo')
.default('memo', '')
.boolean(['debug'])
.demandOption(['amount', 'symbol', 'receiver']).argv
const withdraw = async (amount, symbol, receiver, memo) => {
symbol = symbol.toUpperCase()
const memoText = memo !== '' ? ` (memo: ${memo})` : ''
console.log(
`Transfer ${amount} ${symbol} from ${ACCOUNT} to ${receiver}${memoText}.`
)
const quantity = getQuantity(amount, symbol)
const token_contract = TOKEN_CONTRACTS[symbol]
if (argv.debug)
console.log(
`${amount} ${symbol} converted to '${quantity}' (token_contract: ${token_contract})`
)
pressAnyKey('Press ENTER to continue, or Ctrl + C to stop.', {
ctrlC: 'reject',
})
.then(async () => {
try {
await transferToken({
tokenContract: token_contract,
to: receiver,
quantity: quantity,
memo: `${memo}`,
})
} catch (e) {
console.log(e)
}
})
.catch(() => {
console.log('You pressed Ctrl + C')
})
}
withdraw(argv.amount, argv.symbol, argv.receiver, argv.memo)