|
| 1 | +import { BZZ } from '@ethersphere/bee-js' |
| 2 | +import { LeafCommand, Option } from 'furious-commander' |
| 3 | +import { createKeyValue } from '../../utils/text' |
| 4 | +import { RootCommand } from '../root-command' |
| 5 | + |
| 6 | +export class WithdrawBZZ extends RootCommand implements LeafCommand { |
| 7 | + public readonly name = 'withdraw-bzz' |
| 8 | + |
| 9 | + @Option({ |
| 10 | + key: 'address', |
| 11 | + type: 'hex-string', |
| 12 | + description: 'Target wallet address, must be allowlisted in Bee config', |
| 13 | + required: true, |
| 14 | + }) |
| 15 | + public address!: string |
| 16 | + |
| 17 | + @Option({ |
| 18 | + key: 'bzz', |
| 19 | + description: 'Amount of xBZZ to withdraw to the external wallet', |
| 20 | + type: 'string', |
| 21 | + required: true, |
| 22 | + }) |
| 23 | + public amountBzz!: string |
| 24 | + |
| 25 | + public readonly description = `Withdraw xBZZ to a whitelisted wallet address` |
| 26 | + |
| 27 | + public async run(): Promise<void> { |
| 28 | + super.init() |
| 29 | + |
| 30 | + const amount = BZZ.fromDecimalString(this.amountBzz) |
| 31 | + |
| 32 | + this.console.log('The address you are withdrawing to must be whitelisted in the Bee config.') |
| 33 | + this.console.log('If you receive status code 400, the address may not be whitelisted.') |
| 34 | + this.console.log('') |
| 35 | + |
| 36 | + if (!this.quiet && !this.yes) { |
| 37 | + this.yes = await this.console.confirm( |
| 38 | + `You are about to withdraw ${amount.toDecimalString()} xBZZ to ${ |
| 39 | + this.address |
| 40 | + }, are you sure you wish to proceed?`, |
| 41 | + ) |
| 42 | + } |
| 43 | + |
| 44 | + if (!this.yes && !this.quiet) { |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + const transaction = await this.bee.withdrawBZZToExternalWallet(amount, this.address) |
| 49 | + this.console.log(createKeyValue('Transaction', transaction.represent())) |
| 50 | + this.console.log(createKeyValue('URL', `https://gnosisscan.io/tx/0x${transaction.represent()}`)) |
| 51 | + } |
| 52 | +} |
0 commit comments