"""Prepare an ethereum transaction on a network connected machine.

This module enables you to create a transaction that can then be transferred
to an offline machine which has your ethereum wallet safely stored offline.

It is the first script you need to run if you are creating a new transaction.

Example:
    ::
        $ python tx_prepare.py --ether 2.5 0xb794f5ea0ba39494ce839613fffba74279579268 0xb794f5ea0ba39494ce839613fffba74279579268

Attributes:
    parser (argpase.ArgumentParser): Helper to provide CLI.
    nonce_payload (dict): Request body when fetching nonce from blockchain.
    nonce_response (requests.Response): Response object for nonce request.
    tx_count (int): Number of previous transactions from sender wallet (nonce).
    gas_payload (dict): Request body when fetching gas from blockchain.
    gas_response (requests.Response): Response object for gas request.
    tx_gasprice: Current gas price fetched from blockchain.
"""
import argparse
from decimal import Decimal
import json

from ethereum.transactions import Transaction
import requests
from rlp import encode
from rlp.utils import decode_hex, encode_hex, str_to_bytes

parser = argparse.ArgumentParser()
parser.add_argument('amount')
parser.add_argument('from_addr')
parser.add_argument('to_addr')
parser.add_argument('--geth_rpc', default="http://localhost:8545")
parser.add_argument('--output', default="ethoff.tx")
parser.add_argument('--ether', default=False, action='store_true')
args = parser.parse_args()

# Fetch nonce from the blockchain
nonce_payload = {
    'jsonrpc': '2.0',
    'method': 'eth_getTransactionCount',
    'params': [args.from_addr, 'latest'],
    'id': 1
}
nonce_response = requests.post(
    args.geth_rpc,
    data=json.dumps(nonce_payload)
)

tx_count = int(nonce_response.json()[u'result'], 16)

# Fetch gasprice from the blockchain
gas_payload = {
    'jsonrpc': '2.0',
    'method': 'eth_gasPrice',
    'params': [],
    'id': 73
}
gas_response = requests.post(
    args.geth_rpc,
    data=json.dumps(gas_payload)
)
tx_gasprice = int(gas_response.json()[u'result'], 16)

if args.ether:
    amount = Decimal(args.amount) * 10**18
else:
    amount = Decimal(args.amount)

# Creation transaction, value in wei
tx = Transaction(
    nonce=tx_count,
    gasprice=tx_gasprice,
    startgas=21000,
    to=decode_hex(args.to_addr[2:]),
    value=int(amount),
    data=''
)
tx_hex = '0x' + encode_hex(encode(tx))
tx_wei = str_to_bytes(str(tx.value))
tx_eth = str_to_bytes(str(Decimal(tx.value) / 10**18))

# Output some transaction information
print('======================================================')
print('                  Gas Price: ' + str(tx_gasprice))
print('Transaction amount (in wei): ' + tx_wei)
print('Transaction amount (in eth): ' + tx_eth)
print('                       From: ' + args.from_addr)
print('                 From Nonce: ' + str(tx_count))
print('                Destination: Ox' + encode_hex(tx.to))
print('======================================================')

# Write unsigned transaction to file
open(args.output, 'w').write(tx_hex)
print('Unsigned transaction saved as file: ' + args.output)
print('Unsigned transaction is: ' + tx_hex)
print('======================================================')

@@ -901,16 +901,22 @@
 gasprice
+ (int)
 : Curren
@@ -952,16 +952,234 @@
 kchain.%0A
+    tx (ethereum.transactions.Transaction): Object to build transaction.%0A    tx_wei (bytes): Transaction ammount in wei.%0A    tx_eth (bytes): Transaction ammount in eth.%0A    tx_hex (bytes): Unsigned transaction in hex.%0A
 %22%22%22%0Aimpo
@@ -2609,47 +2609,8 @@
 '%0A)%0A
-tx_hex = '0x' + encode_hex(encode(tx))%0A
 tx_w
@@ -3228,16 +3228,55 @@
 to file%0A
+tx_hex = '0x' + encode_hex(encode(tx))%0A
 open(arg

Add remaining module variables to docblocks.