commit 3b0f1e450077a7cbb67aae1ea513cd72290a3093
parent 84852e1a034270b8931168bba46c9c48cbd931f3
Author: nolash <dev@holbrook.no>
Date: Mon, 7 Dec 2020 11:41:06 +0100
Add gift executable
Diffstat:
4 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/python/CHANGELOG b/python/CHANGELOG
@@ -1,3 +1,5 @@
+* 0.0.3
+ - Add gift executable
* 0.0.2
- Move deploy script to package
* 0.0.1
diff --git a/python/giftable_erc20_token/runnable/gift.py b/python/giftable_erc20_token/runnable/gift.py
@@ -0,0 +1,59 @@
+"""Mints and gifts tokens to a given address
+
+.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
+.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
+
+"""
+
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# standard imports
+import os
+import json
+import argparse
+import logging
+
+# third-party imports
+import web3
+
+logging.basicConfig(level=logging.WARNING)
+logg = logging.getLogger()
+
+logging.getLogger('web3').setLevel(logging.WARNING)
+logging.getLogger('urllib3').setLevel(logging.WARNING)
+
+argparser = argparse.ArgumentParser()
+argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
+argparser.add_argument('-t', '--token-address', required='True', dest='t', type=str, help='Giftable token address')
+argparser.add_argument('-m', '--minter-address', dest='m', type=str, help='Minter account address')
+argparser.add_argument('--contracts-dir', dest='contracts_dir', type=str, default='.', help='Directory containing bytecode and abi')
+argparser.add_argument('-v', action='store_true', help='Be verbose')
+argparser.add_argument('-r', '--recipient-address', dest='r', type=str, help='Recipient account address')
+argparser.add_argument('amount', type=int, help='Amount of tokens to mint and gift')
+args = argparser.parse_args()
+
+if args.v:
+ logg.setLevel(logging.DEBUG)
+
+def main():
+ w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
+
+ f = open(os.path.join(args.contracts_dir, 'GiftableToken.abi.json'), 'r')
+ abi = json.load(f)
+ f.close()
+
+ c = w3.eth.contract(abi=abi, address=args.t)
+ if args.m != None:
+ w3.eth.defaultAccount = web3.Web3.toChecksumAddress(args.m)
+ else:
+ w3.eth.defaultAccount = w3.eth.accounts[0]
+
+ recipient = w3.eth.defaultAccount
+ if args.r != None:
+ recipient = web3.Web3.toChecksumAddress(args.r)
+
+ c.functions.mint(args.amount).transact()
+ tx = c.functions.transfer(recipient, args.amount).transact()
+
+ print(tx.hex())
+
diff --git a/python/setup.cfg b/python/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = giftable-erc20-token
-version = 0.0.2
+version = 0.0.3
description = Simple ERC20 contract with deployment script that lets any address mint and gift itself tokens.
author = Louis Holbrook
author_email = dev@holbrook.no
@@ -30,3 +30,4 @@ install_requires =
[options.entry_points]
console_scripts =
giftable-token-deploy = giftable_erc20_token.runnable.deploy:main
+ giftable-token-gift = giftable_erc20_token.runnable.gift:main
diff --git a/solidity/Makefile b/solidity/Makefile
@@ -0,0 +1,8 @@
+all:
+ solc --bin GiftableToken.sol | awk 'NR>3' > GiftableToken.bin
+ truncate -s -1 GiftableToken.bin
+ solc --abi GiftableToken.sol | awk 'NR>3' > GiftableToken.abi.json
+
+#install: all
+# cp -v *{json,bin} ../python/giftable_erc20_token/data/
+