waspsting.py - move all SteemEngine tokens to destination account

in #steem-engine4 years ago

Another Useful Utility

waspsting.png
I was asked if there was an easy way to transfer all steem-engine tokens to another account, and of course, there isn't. And I was sure I could spit one out in no time. Well, it was a tad harder than I expected because of the precision of each token is different, so that was added to it.

This script uses standard beem (as opposed to my behive) and system libraries only.

An always up to date version will be in this gist: waspsting.py

Code is below for those that don't want to click away.

#!/usr/bin/env python3
import time
from pprint import pprint

from beem import Steem
from beem.wallet import Wallet
from steemengine.tokens import Tokens
from steemengine.wallet import Wallet as seWallet


def wasp():
    """ Go down the list of Steem Engine tokens and transfer full balance to destination"""
    send_to = input('Enter destination: ')
    active_wif = input('Enter your Active Key: ')
    steem = Steem(keys=[active_wif], nodes='https://api.steemit.com')
    w = Wallet(steem_instance=steem)
    t = Tokens()    
    usr = w.getAccountFromPrivateKey(active_wif)
    sew = seWallet(account=usr, steem_instance=steem)
    tokens = sew.get_balances()
    for token in tokens:
        symbol = token['symbol']
        info = t.get_token(symbol)
        p = info['precision']
        b = float(token['balance'])
        balance = float(f'{b:.{p}f}')
        if balance > 0:
            print(f'[ Transfering {balance} of {symbol} to {send_to} ]')
            #pprint(sew.transfer(send_to, balance, symbol, memo="waspsting.py transfer")
            sew.transfer(send_to, balance, symbol, memo="waspsting.py transfer")
            time.sleep(1)
    return None


if __name__ == "__main__":
    wasp()

Granted this utility is not very Hive related but useful nonetheless with the drama in the *-engine world now.

Thanks and take care,
Michael Garcia a.k.a. @TheCrazyGM
signature_fancy.png