def transferEther(account):
    os.system('clear')
    print("\nTransfer Ether -----------------------------------------------\n")
    print("Please, write the account that will receive the ETH")
    account2 = input("Account to transfer: ")
    os.system('clear')
    print("\nTransfer Ether -----------------------------------------------\n")
    print("Now write your private key")
    print("\nWARNING: Never let anyone to have your private key")
    print(
        "This program will use it only once to do the transfer and then delete it"
    )
    privateKey = input("\nPrivate Key of your account: ")
    os.system('clear')
    print("\nTransfer Ether -----------------------------------------------\n")
    print("Private Key received\n")
    value = input("Ether amount to send: ")
    gas = input("Gas amount to use: ")
    gasPrice = input("Gas price: ")
    print("Proceed: 1   ||  Cancel: 2")
    option = input("Confirm command: ")
    if (int(option) == 1):
        transactionEther(account, account2, privateKey, value, gas, gasPrice)
    elif (int(option) == 2):
        os.system('clear')
        manage_account.login(account)
    else:
        print("Invalid option")
def transactionEther(account, account2, privateKey, value, gas, gasPrice):
    nonce = web3.eth.getTransactionCount(account)
    tx = {
        'nonce': nonce,
        'to': account2,
        'value': web3.toWei(value, 'ether'),
        'gas': int(gas),
        'gasPrice': web3.toWei(int(gasPrice), 'gwei')
    }

    #Signing transaction
    signed_transaction = web3.eth.account.signTransaction(tx, privateKey)

    #Send transaction to the network
    raw_transaction = web3.eth.sendRawTransaction(
        signed_transaction.rawTransaction)
    tx_hash = web3.toHex(raw_transaction)
    print("\nTransaction hash in hexbyte: " + str(tx_hash))

    txtEther(account, account2, value, gas, gasPrice, tx_hash)
    print("Operation completed")
    print(
        "\nThe file '02_Transaction_Completed.txt' has been succesfully updated"
    )
    input("\nPress enter to return")
    os.system('clear')
    manage_account.login(account)
def transferTokens(account):
    os.system('clear')
    print("\nTransfer Tokens ----------------------------------------------\n")
    print("Please, write the address that will receive the Tokens")
    contract_address = input("Address to transfer: ")
    os.system('clear')
    print("\nTransfer Tokens ----------------------------------------------\n")
    print("Now write your private key")
    print("\nWARNING: Never let anyone to have your private key")
    print(
        "This program will use it only once to do the transfer and then delete it"
    )
    privateKey = input("\nPrivate Key of your account: ")
    os.system('clear')
    print("\nTransfer Tokens ----------------------------------------------\n")
    print("Private Key received\n")
    token_val = input("Amount of Tokens to send: ")
    gas = input("Gas amount to use: ")
    gasPrice = input("Gas price: ")
    print("Proceed: 1   ||  Cancel: 2")
    option = input("Confirm command: ")
    if (int(option) == 1):
        transactionTokens(account, contract_address, privateKey, token_val,
                          gas, gasPrice)
    elif (int(option) == 2):
        os.system('clear')
        manage_account.login(account)
    else:
        print("Invalid option")
示例#4
0
def optionSelection(option):
    if (int(option) == 1):
        print("\n ------------------- Account login -------------------")
        account = input("Public key: ")
        os.system('clear')
        manage_account.login(account)
    elif (int(option) == 2):
        print("\n ------------------- New account -------------------")
        print("1: Create account")
        print("2: Sign and validate account")
        n_option = input("Choose an option: ")
        if (int(n_option) == 1):
            os.system('clear')
            create_account.createAccount()
        elif (int(n_option) == 2):
            os.system('clear')
            print(
                "\n ------------------- Sign and validate account -------------------"
            )
            print("\nAdd your address and private key")
            print("You could find them in the '01_Account_Info.txt' file")
            print("\nWARNING: Never let anyone to have your private key\n")
            print("You may need some Ether to do the transaction")
            address = input("\nAddress of new created account: ")
            private_key = input("Private key of new account: ")
            create_account.transactionAccount(address, private_key, web3)
        else:
            print("Invalid option")
    elif (int(option) == 3):
        os.system('clear')
        explore_blocks.exploreBlocks(web3)
def transferMain(account):
    print("\nTransfer Ether/Tokens ----------------------------------------\n")
    print("\nYou now can send Ether to other accounts")
    print("(As well as tokens)\n")
    print("Send Ether: 1  ||  Send Tokens: 2  ||  Return: 3")
    option = input("\nChoose an option: ")
    if (int(option) == 1):
        transferEther(account)
    elif (int(option) == 2):
        transferTokens(account)
    elif (int(option) == 3):
        os.system('clear')
        manage_account.login(account)
    else:
        print("Invalid option")
def transactionTokens(account, contract_address, privateKey, token_val, gas,
                      gasPrice):

    nonce = w3.eth.getTransactionCount(account)
    contract_add = w3.toChecksumAddress(contract_address)
    contract = w3.eth.contract(contract_add, abi=EIP20_ABI)
    tx_contract = contract.functions.transfer(contract_address,
                                              token_val).buildTransaction({
                                                  'chainId':
                                                  1,
                                                  'gas':
                                                  gas,
                                                  'value':
                                                  0,
                                                  'gasPrice':
                                                  web3.toWei(
                                                      int(gasPrice), 'gwei'),
                                                  'nonce':
                                                  nonce
                                              })

    #Signing transaction
    signed_transaction = web3.eth.account.signTransaction(
        tx_contract, privateKey)

    #Send transaction to the network
    raw_transaction = web3.eth.sendRawTransaction(
        signed_transaction.rawTransaction)
    tx_hash = web3.toHex(raw_transaction)
    print("\nTransaction hash in hexbyte: " + str(tx_hash))

    txtTokens(account, contract_address, token_val, gas, gasPrice, tx_hash)
    print(
        "\nThe file '03_Transaction_Token_Completed.txt' has been succesfully updated"
    )
    input("\nPress enter to return")
    os.system('clear')
    manage_account.login(account)