def approveTokenTransfer(state):
    web3 = web3_client(state.get('network'))
    bountiesContract = getBountiesContract(state.get('network'))
    token = getTokenContract(state.get('network'),
                             to_checksum_address(state.get('token_address')))

    tx = token.functions.approve(to_checksum_address(
        bountiesContract.address), state.get('amount')).buildTransaction({
            'gasPrice':
            web3.toWei(state.get('gas_price'), 'gwei'),
            'gas':
            state.get('gas_limit'),
            'nonce':
            web3.eth.getTransactionCount(
                to_checksum_address(state.get('wallet').get('address'))),
        })

    signed = web3.eth.account.signTransaction(
        tx, private_key=state.get('wallet').get('private_key'))

    # send transaction and wait for receipt
    print('Approving token usage... ', end='', flush=True)
    receipt = web3.eth.waitForTransactionReceipt(
        web3.eth.sendRawTransaction(signed.rawTransaction))
    puts(colored.green(web3.toHex(receipt.transactionHash)))
示例#2
0
def issueAndActivateBounty(state, ipfsHash):
    web3 = web3_client(state.get('network'))
    bountiesContract = getBountiesContract(state.get('network'))

    # build transaction
    tx = bountiesContract.functions.issueAndActivateBounty(
        state.get('wallet').get('address'),
        9999999999,  # 11/20/2286, https://github.com/Bounties-Network/StandardBounties/issues/25
        ipfsHash,
        state.get('amount'),
        '0x0000000000000000000000000000000000000000',
        state.get('token_address') !=
        '0x0000000000000000000000000000000000000000',
        to_checksum_address(state.get('token_address')),
        state.get('amount')).buildTransaction({
            'from':
            state.get('wallet').get('address'),
            'value':
            state.get('amount') if state.get('token_address')
            == '0x0000000000000000000000000000000000000000' else 0,
            'gasPrice':
            web3.toWei(state.get('gas_price'), 'gwei'),
            'gas':
            state.get('gas_limit'),
            'nonce':
            web3.eth.getTransactionCount(state.get('wallet').get('address'))
        })

    signed = web3.eth.account.signTransaction(
        tx, private_key=state.get('wallet').get('private_key'))

    old_id = bountiesContract.functions.getNumBounties().call()

    # send transaction and wait for receipt
    print('Funding bounty... ', end='', flush=True)
    receipt = web3.eth.waitForTransactionReceipt(
        web3.eth.sendRawTransaction(signed.rawTransaction))
    new_id = bountiesContract.functions.getNumBounties().call()
    puts(colored.green(web3.toHex(receipt.transactionHash)))

    return old_id < new_id, old_id
def network(ctx, param, value):
    try:
        getBountiesContract(value)
    except UnsupportedNetworkException:
        raise BadParameter('unsupported network')
    return value