Skip to content

Instantly share code, notes, and snippets.

@nnamon
Created April 3, 2019 08:09
Show Gist options
  • Save nnamon/8bc05c21022a503cc2390f4488654c84 to your computer and use it in GitHub Desktop.
Save nnamon/8bc05c21022a503cc2390f4488654c84 to your computer and use it in GitHub Desktop.
Multi Transfer Many to One Address
#!/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