eth-erc20

ERC20 interface and example giftable token contract
Log | Files | Refs | LICENSE

commit f2d35bf3fdb720fab8e2e83d32707465004aacb1
Author: nolash <dev@holbrook.no>
Date:   Tue, 17 Nov 2020 19:23:57 +0100

Initial commit

Diffstat:
ACHANGELOG | 3+++
AGiftableToken.abi.json | 1+
AGiftableToken.bin | 2++
AGiftableToken.sol | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALICENSE | 45+++++++++++++++++++++++++++++++++++++++++++++
AVERSION | 1+
Adeploy.py | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 285 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -0,0 +1,3 @@ +* 0.0.1 + - Adapt Bancor ERC20 token contract + - Add deploy-and-gift script diff --git a/GiftableToken.abi.json b/GiftableToken.abi.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_initialSupply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_oldTotal","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newTotal","type":"uint256"}],"name":"ChangedSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"gift","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/GiftableToken.bin b/GiftableToken.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b50604051620012db380380620012db833981810160405260808110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b838201915060208201858111156200006f57600080fd5b82518660018202830111640100000000821117156200008d57600080fd5b8083526020830192505050908051906020019080838360005b83811015620000c3578082015181840152602081019050620000a6565b50505050905090810190601f168015620000f15780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200011557600080fd5b838201915060208201858111156200012c57600080fd5b82518660018202830111640100000000821117156200014a57600080fd5b8083526020830192505050908051906020019080838360005b838110156200018057808201518184015260208101905062000163565b50505050905090810190601f168015620001ae5780820380516001836020036101000a031916815260200191505b506040526020018051906020019092919080519060200190929190505050600084511162000244576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f4552525f494e56414c49445f4e414d450000000000000000000000000000000081525060200191505060405180910390fd5b6000835111620002bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4552525f494e56414c49445f53594d424f4c000000000000000000000000000081525060200191505060405180910390fd5b8360009080519060200190620002d49291906200035e565b508260019080519060200190620002ed9291906200035e565b5081600260006101000a81548160ff021916908360ff1602179055508060038190555080600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050505062000414565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620003965760008555620003e2565b82601f10620003b157805160ff1916838001178555620003e2565b82800160010185558215620003e2579182015b82811115620003e1578251825591602001919060010190620003c4565b5b509050620003f19190620003f5565b5090565b5b8082111562000410576000816000905550600101620003f6565b5090565b610eb780620004246000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c806370a082311161006657806370a082311461024d57806395d89b41146102a5578063a9059cbb14610328578063cbce4c971461038c578063dd62ed3e146103f05761009e565b806306fdde03146100a3578063095ea7b31461012657806318160ddd1461018a57806323b872dd146101a8578063313ce5671461022c575b600080fd5b6100ab610468565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100eb5780820151818401526020810190506100d0565b50505050905090810190601f1680156101185780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101726004803603604081101561013c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610506565b60405180821515815260200191505060405180910390f35b610192610700565b6040518082815260200191505060405180910390f35b610214600480360360608110156101be57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610706565b60405180821515815260200191505060405180910390f35b610234610997565b604051808260ff16815260200191505060405180910390f35b61028f6004803603602081101561026357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109aa565b6040518082815260200191505060405180910390f35b6102ad6109c2565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102ed5780820151818401526020810190506102d2565b50505050905090810190601f16801561031a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103746004803603604081101561033e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a60565b60405180821515815260200191505060405180910390f35b6103d8600480360360408110156103a257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610be6565b60405180821515815260200191505060405180910390f35b6104526004803603604081101561040657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610db6565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104fe5780601f106104d3576101008083540402835291602001916104fe565b820191906000526020600020905b8154815290600101906020018083116104e157829003601f168201915b505050505081565b60008261051281610ddb565b600083148061059d57506000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b61060f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4552525f494e56414c49445f414d4f554e54000000000000000000000000000081525060200191505060405180910390fd5b82600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a3600191505092915050565b60035481565b60008361071281610ddb565b8361071c81610ddb565b83600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555083600460008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403600460008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555083600460008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401600460008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a36001925050509392505050565b600260009054906101000a900460ff1681565b60046020528060005260406000206000915090505481565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a585780601f10610a2d57610100808354040283529160200191610a58565b820191906000526020600020905b815481529060010190602001808311610a3b57829003601f168201915b505050505081565b600082610a6c81610ddb565b82600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555082600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3600191505092915050565b600082610bf281610ddb565b82600354016003819055506000600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905083600460008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401600460008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055507f5f8b22485eeda034e9b3b8726a34dbff9aeea5105cbefd66dac32e2890de592e81600460008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054604051808381526020018281526020019250505060405180910390a18473ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a360019250505092915050565b6005602052816000526040600020602052806000526040600020600091509150505481565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610e7e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f4552525f494e56414c49445f414444524553530000000000000000000000000081525060200191505060405180910390fd5b5056fea2646970667358221220c03c933fbef61b72e1494c56e20cc2e1a0f185aed6ac65f30476e92f2c11677564736f6c63430007040033 +\ No newline at end of file diff --git a/GiftableToken.sol b/GiftableToken.sol @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: SEE LICENSE IN LICENSE +pragma solidity ^0.7.4; + +/* + * This is a MOCK token used for DEVELOPMENT PURPOSES ONLY. + * It allows anyone to freely mint tokens with themselves as beneficiaries + * Code is based on the ERC20Token contract from Bancor's contracts-solidity repository + * + * @dev ERC20 Standard Token implementation +*/ + +contract GiftableToken { //is IERC20Token, Utils { + //using SafeMath for uint256; + + string public name; + string public symbol; + uint8 public decimals; + uint256 public totalSupply; + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + /** + * @dev triggered when tokens are transferred between wallets + * + * @param _from source address + * @param _to target address + * @param _value transfer amount + */ + event Transfer(address indexed _from, address indexed _to, uint256 _value); + + /** + * @dev triggered when a wallet allows another wallet to transfer tokens from on its behalf + * + * @param _owner wallet that approves the allowance + * @param _spender wallet that receives the allowance + * @param _value allowance amount + */ + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + event ChangedSupply(uint256 _oldTotal, uint256 _newTotal); + + /** + * @dev initializes a new ERC20Token instance + * + * @param _name token name + * @param _symbol token symbol + * @param _decimals decimal points, for display purposes + * @param _initialSupply total supply of token units + */ + constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) { + // validate input + require(bytes(_name).length > 0, "ERR_INVALID_NAME"); + require(bytes(_symbol).length > 0, "ERR_INVALID_SYMBOL"); + + name = _name; + symbol = _symbol; + decimals = _decimals; + totalSupply = _initialSupply; + balanceOf[msg.sender] = _initialSupply; + } + + // validates an address - currently only checks that it isn't null + modifier validAddress(address _address) { + _validAddress(_address); + _; + } + + // error message binary size optimization + function _validAddress(address _address) internal pure { + require(_address != address(0), "ERR_INVALID_ADDRESS"); + } + + + function gift(address _to, uint256 _value) + public + virtual + validAddress(_to) + returns (bool) + { + totalSupply = totalSupply + _value; + uint256 oldSupply = balanceOf[_to]; + balanceOf[_to] = balanceOf[_to] + _value; + emit ChangedSupply(oldSupply, balanceOf[_to]); + emit Transfer(address(0x00), _to, _value); + return true; + } + + /** + * @dev transfers tokens to a given address + * throws on any error rather then return a false flag to minimize user errors + * + * @param _to target address + * @param _value transfer amount + * + * @return true if the transfer was successful, false if it wasn't + */ + function transfer(address _to, uint256 _value) + public + virtual + validAddress(_to) + returns (bool) + { + balanceOf[msg.sender] = balanceOf[msg.sender] - _value; + balanceOf[_to] = balanceOf[_to] + _value; + emit Transfer(msg.sender, _to, _value); + return true; + } + + /** + * @dev transfers tokens to a given address on behalf of another address + * throws on any error rather then return a false flag to minimize user errors + * + * @param _from source address + * @param _to target address + * @param _value transfer amount + * + * @return true if the transfer was successful, false if it wasn't + */ + function transferFrom(address _from, address _to, uint256 _value) + public + virtual + validAddress(_from) + validAddress(_to) + returns (bool) + { + allowance[_from][msg.sender] = allowance[_from][msg.sender] - _value; + balanceOf[_from] = balanceOf[_from] - _value; + balanceOf[_to] = balanceOf[_to] + _value; + emit Transfer(_from, _to, _value); + return true; + } + + /** + * @dev allows another account/contract to transfers tokens on behalf of the caller + * throws on any error rather then return a false flag to minimize user errors + * + * also, to minimize the risk of the approve/transferFrom attack vector + * (see https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/), approve has to be called twice + * in 2 separate transactions - once to change the allowance to 0 and secondly to change it to the new allowance value + * + * @param _spender approved address + * @param _value allowance amount + * + * @return true if the approval was successful, false if it wasn't + */ + function approve(address _spender, uint256 _value) + public + virtual + validAddress(_spender) + returns (bool) + { + // if the allowance isn't 0, it can only be updated to 0 to prevent an allowance change immediately after withdrawal + require(_value == 0 || allowance[msg.sender][_spender] == 0, "ERR_INVALID_AMOUNT"); + + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } +} diff --git a/LICENSE b/LICENSE @@ -0,0 +1,45 @@ + Bprotocol Foundation (Bancor) LICENSE + +1. SUBJECT TO THE PROVISIONS SET FORTH HEREIN, INCLUDING “EFFECTIVE DATE”, YOU CAN + USE THIS CODE, FILE AND/OR SOFTWARE (“SOFTWARE”) ONLY IN CONNECTION WITH THE + BANCOR LIQUIDITY NETWORK AND/OR THE USE OF BNT ("PERMITTED USE"). ANY OTHER USE IS + PROHIBITED UNLESS THE USER SHALL RECEIVE AN EXPLICIT PRIOR WRITTEN APPROVAL FROM + BPROTOCOL FOUNDATION (BANCOR) TO DO SO (PLEASE CONTACT license@bancor.network IN + THIS REGARD), WHICH APPROVAL, IF GIVEN, MAY REQUIRE THE OBTAINMENT OF SEPARATE + LICENSE UNDER A DIFFERENT LICENSING MODEL. USING THIS SOFTWARE NOT IN THE FRAME OF + SUCH PERMITTED USE MAY, AMONG OTHERS, ALSO BREACH PATENT RIGHTS CONCERNING PATENTS + WHICH ARE EMBODIED/INCORPORATED/USED IN THIS SOFTWARE. + +2. ANY SUCH PERMITTED USE SHOULD ALSO COMPLY WITH THE TERMS BELOW. + +3. Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: +A. Redistributions of source code must retain the above copyright notice, this list + of conditions and the following disclaimer. +B. Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or other + materials provided with the distribution. +C. Neither the name of the copyright holder nor the names of its contributors may be + used to endorse or promote products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +EFFECTIVE DATE: THIS LICENSE SHALL APPLY ONLY TO SOFTWARE (OR ANY VERSION THEREOF), +THAT HAS BEEN PUBLISHED AFTER THE DATE AND TIME THIS LICENSE HAS BEEN FIRST PUBLISHED +(“EFFECTIVE DATE”); Any previous versions published prior to the effective date (“Older Versions”) +shall remain licensed under the Apache License, Version 2.0 (the "Older Versions License"); +You may obtain a copy of the Older Version License at http://www.apache.org/licenses/LICENSE-2.0 +you may not use this file except in compliance with the Older Version License. Unless +required by applicable law or agreed to in writing, Older Versions distributed under the +Older Version License are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, either express or implied. See the Older Version License for the specific +language governing permissions and limitations under the Older Version License. diff --git a/VERSION b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/deploy.py b/deploy.py @@ -0,0 +1,74 @@ +"""Deploys giftable token, and optionally gifts a set amount to all accounts in wallet + +.. moduleauthor:: Louis Holbrook <dev@holbrook.no> +.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 + +""" + +# SPDX-License-Identifier: GPL-3.0-or-later + +# standard imports +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('-g', '--gift', dest='g', action='store_true', help='If set, tokens will be gifted to all accounts in provider wallet') +argparser.add_argument('-n', '--name', dest='n', default='Giftable Token', type=str, help='Token name') +argparser.add_argument('-s', '--symbol', dest='s', default='GFT', type=str, help='Token symbol') +argparser.add_argument('-d', '--decimals', dest='d', default=18, type=int, help='Token decimals') +argparser.add_argument('-a', '--account', dest='a', type=str, help='Owner account. If not specified, first account in wallet will be used') +argparser.add_argument('-v', action='store_true', help='Be verbose') +argparser.add_argument('amount', type=int, help='Initial token supply (will be owned by contract creator)') +args = argparser.parse_args() + +if args.v: + logg.setLevel(logging.DEBUG) + +if __name__ == '__main__': + w3 = web3.Web3(web3.Web3.HTTPProvider(args.p)) + + f = open('./GiftableToken.abi.json', 'r') + abi = json.load(f) + f.close() + + f = open('./GiftableToken.bin', 'r') + bytecode = f.read() + f.close() + + if args.a != None: + a = web3.Web3.toChecksumAddress(args.a) + w3.eth.defaultAccount = a + else: + w3.eth.defaultAccount = w3.eth.accounts[0] + + c = w3.eth.contract(abi=abi, bytecode=bytecode) + tx_hash = c.constructor(args.n, args.s, args.d, args.amount).transact() + rcpt = w3.eth.getTransactionReceipt(tx_hash) + address = rcpt.contractAddress + c = w3.eth.contract(abi=abi, address=address) + + logg.debug('construct tx {} address {}'.format(tx_hash.hex(), address)) + balance = c.functions.balanceOf(w3.eth.defaultAccount).call() + logg.info('balance {}: {}'.format(w3.eth.defaultAccount, balance)) + + if args.g: + for a in w3.eth.accounts: + if a == w3.eth.defaultAccount: + continue + tx_hash = c.functions.gift(a, args.amount).transact() + rcpt = w3.eth.getTransactionReceipt(tx_hash) + balance = c.functions.balanceOf(a).call() + logg.info('balance {}: {}'.format(a, balance)) + + print(address)