Created
April 3, 2019 08:09
-
-
Save nnamon/8bc05c21022a503cc2390f4488654c84 to your computer and use it in GitHub Desktop.
Multi Transfer Many to One Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pyzil.zilliqa import chain | |
from pyzil.account import Account | |
import multiprocessing | |
from itertools import repeat | |
import argparse | |
PROCESS_SIZE = 80 | |
chain.set_active_chain(chain.MainNet) | |
def main(): | |
parser = argparse.ArgumentParser(description='Check the balance of multiple Zilliqa addresses.') | |
parser.add_argument('--privkeys', required=True, | |
help='Specify the file containing a list of addresses to from.') | |
parser.add_argument('--receipient', required=True, help='The receiving address to send to.') | |
parser.add_argument('--amount', required=True, help='The amount to send.', type=float) | |
args = parser.parse_args() | |
mass_transfer(args.privkeys, args.receipient, args.amount) | |
def mass_transfer(filename, receipient, amount=0.001): | |
entries = open(filename).read().strip().split("\n") | |
pool = multiprocessing.Pool(PROCESS_SIZE) | |
results = pool.map(send, zip(entries, repeat(receipient), repeat(amount))) | |
for privkey, result in zip(entries, results): | |
print(privkey, result) | |
def send(args): | |
privkey, receipient, amount = args | |
account = Account(private_key=privkey) | |
try: | |
result = account.transfer(receipient, amount) | |
return result | |
except ValueError: | |
return "Insufficient balance." | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment