Beispiel #1
0
def sendToken(keyfile, contractAddress, toAddress, value):
    # gen acct
    acct = web3tools.genAcct(keyfile)

    # gen contract interface
    sourcefile = 'contracts/WaltonToken.sol'
    contractInterface = web3tools.compileContract(sourcefile)

    contractOnline = w3.eth.contract(abi=contractInterface['abi'],
                                     address=contractAddress)

    # form tx
    construct_txn = contractOnline.functions.transfer(
        toAddress, value).buildTransaction({
            'from':
            acct.address,
            'nonce':
            w3.eth.getTransactionCount(acct.address),
            'gas':
            1728712,
            'gasPrice':
            int(w3.eth.gasPrice * gasPriceInc)
        })

    # sign with acct, then send raw transaction
    signed = acct.signTransaction(construct_txn)
    tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction)

    # waiting for receipt
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    pprint(tx_receipt)
    return tx_receipt
Beispiel #2
0
def showLockerTest():
    #showLocker()
    
    lockersourcefile = 'contracts/WaltonTokenLocker.sol'
    contractInterface = web3tools.compileContract(lockersourcefile)

    locker = '0x2990c339470fe33f3C17E784e87e3c3f1e14BCEC'
    web3tools.showLockerContract(contractInterface, locker)
Beispiel #3
0
def showTokenBalance(contractAddress, real=0):
    # gen contract interface
    sourcefile = 'contracts/WaltonToken.sol'
    contractInterface = web3tools.compileContract(sourcefile)

    contractOnline = w3.eth.contract(abi=contractInterface['abi'],
                                     address=contractAddress)
    name = contractOnline.functions.name().call()
    symbol = contractOnline.functions.symbol().call()
    decimals = contractOnline.functions.decimals().call()
    totalSupply = contractOnline.functions.totalSupply().call()

    print('\n'
          '---------------------------------------------------------------\n'
          'token information: \n'
          '-----------------+---------------------------------------------\n'
          'contractAddress  | {}\n'
          'name             | {}\n'
          'symbol           | {}\n'
          'decimals         | {}\n'
          'totalSupply      | {:,}\n'
          '-----------------+---------------------------------------------'.
          format(contractAddress, name, symbol, decimals,
                 totalSupply / 10**18))

    if real:
        addresses = [
            '0xD93fB95dA2148BF3cb1d30d7498B447bC240F3D7',
            '0xc2c4CE063aF8f547E596b6Fa3771Bf423D495817',
            '0xC04608b9d32F74D88b40e837DA740B297E2940Ab',
            '0xCCd8e06861943fDaBf413628F272d21Bd0E08EDB',
            '0x01677C56443Fb9537Bf6481a86502a4fF5C995c7',
            '0x9b2922B14f9d3286Cf9941389b764F228B97d52D',
            '0xD1cE4C4ad8770824b068848dD36c05b0b74F28Ec',
            '0x907D4290044c176b77d0DE9C7526aeA4665d4Aaf',
            '0x020675cd807d796f4e676ec76b3A162988052020',
            '0x34D91484307F2e1A698b247931280Bd6c89B965e',
            '0x683E9560CD97b3F92EA005Cefb90E79BC2a1388A',
        ]
    else:
        addresses = [
            '0x2990c339470fe33f3C17E784e87e3c3f1e14BCEC',
            '0x18089Cb45906F19889c44c23A86b96062C245865',
            '0x5b21AA23A11c03b6C35A26722a8D3912C88E9c28',
            '0x73C4a7a90ebB9b02f459cF6268D2EA6e2a9161Cc',
            '0x9386d429Ab977E0C5d7eCd7aD23BD7704Ec4e0C7',
            '0xE423410c734FE690B8966a33359B4b2AbA673E03',
            '0xfc45bc7e9d62956A6Cd19435FfFeDD255CB66B09'
        ]

    print('     address                                  |  balance')
    print('----------------------------------------------+----------------')
    for owner in addresses:
        bal = contractOnline.functions.balanceOf(owner).call()
        print('{}    |    {:<12,}'.format(owner, bal / 10**18))

    print('----------------------------------------------+----------------\n')
Beispiel #4
0
def deployLocker(lockerkeyfile, name, tokenAddress, beneficiary,
                 releaseTimestamp):
    # deploy contract locker

    # keyfile to account
    acct = web3tools.genAcct(lockerkeyfile)

    # *.sol to contract interface
    lockersourcefile = 'contracts/WaltonTokenLocker.sol'
    contractInterface = web3tools.compileContract(lockersourcefile)

    # abi & bin to contract
    contract = w3.eth.contract(abi=contractInterface['abi'],
                               bytecode=contractInterface['bin'])
    # form tx
    construct_txn = contract.constructor(
        name, tokenAddress, beneficiary, releaseTimestamp).buildTransaction({
            'from':
            acct.address,
            'nonce':
            w3.eth.getTransactionCount(acct.address),
            'gas':
            1728712,
            'gasPrice':
            int(w3.eth.gasPrice * gasPriceInc)
        })

    # sign with acct, then send raw transaction
    signed = acct.signTransaction(construct_txn)
    tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction)

    # waiting for receipt
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    pprint(tx_receipt)

    # get address of contract
    contractAddress = tx_receipt.get('contractAddress')
    print('contractAddress contract address is : ', contractAddress)
    #web3tools.showLockerContract(contractInterface, contractAddress)
    return contractAddress
Beispiel #5
0
def lockercall(keyfile, contractAddress, func, releaseTime=1566403200):
    # gen acct
    acct = web3tools.genAcct(keyfile)

    # gen contract interface
    sourcefile = 'contracts/WaltonTokenLocker.sol'
    contractInterface = web3tools.compileContract(sourcefile)

    contractOnline = w3.eth.contract(abi=contractInterface['abi'],
                                     address=contractAddress)

    # form tx
    if func == 'release':
        contractFunc = contractOnline.functions.release()
    elif func == 'safeRelease':
        contractFunc = contractOnline.functions.safeRelease()
    elif func == 'setReleaseTime':
        contractFunc = contractOnline.functions.setReleaseTime(
            int(releaseTime))

    construct_txn = contractFunc.buildTransaction({
        'from':
        acct.address,
        'nonce':
        w3.eth.getTransactionCount(acct.address),
        'gas':
        1728712,
        'gasPrice':
        int(w3.eth.gasPrice * gasPriceInc)
    })

    # sign with acct, then send raw transaction
    signed = acct.signTransaction(construct_txn)
    tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction)

    # waiting for receipt
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    pprint(tx_receipt)
    return tx_receipt
Beispiel #6
0
from tools import ethtools
from tools import web3tools
import json

if __name__ == '__main__':

    sourcefile = 'contracts/WaltonTokenLocker.sol'
    contractInterface = web3tools.compileContract(sourcefile)
    binstr = contractInterface['bin']
    abistr = contractInterface['abi']

    fbin = open('contracts/WaltonTokenLocker.bin', 'w')
    fabi = open('contracts/WaltonTokenLocker.abi', 'w')
    fbin.write(binstr)
    fabi.write(json.dumps(abistr, indent=4))