Add gift executable

This commit is contained in:
nolash 2020-12-07 11:41:06 +01:00
parent 84852e1a03
commit 3b0f1e4500
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 71 additions and 1 deletions

View File

@ -1,3 +1,5 @@
* 0.0.3
- Add gift executable
* 0.0.2
- Move deploy script to package
* 0.0.1

View File

@ -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())

View File

@ -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

8
solidity/Makefile Normal file
View File

@ -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/