Server Integration

If you only want to use bitcoinpython for its raw speed to lessen the load on your servers, you don’t have to use any of our network capabilities.

Offline Transactions

bitcoinpython supports the signing of transactions for keys in cold storage. First you need to prepare a transaction while connected to the internet using the prepare_transaction() class method of a private key. You must know your address.

>>> from bitcoinpython import PrivateKeyTestnet
>>> from import NetworkAPI, satoshi_to_currency
>>> satoshi_to_currency(NetworkAPI.get_balance_testnet(address), 'usd')
>>> tx_data = PrivateKeyTestnet.prepare_transaction(address, [('n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi', 1, 'jpy')])
>>> tx_data

This performs validation and returns a JSON string containing all the required information to create a transaction. You should then take this to your offline machine and use the sign_transaction() method of your private key.

>>> tx_hex = key.sign_transaction(tx_data)
>>> tx_hex

Finally, bring this transaction back to your connected device and broadcast it.

>>> from import NetworkAPI
>>> NetworkAPI.broadcast_tx_testnet(tx_hex)

Blockchain Storage

bitcoinpython allows you to easily store messages or data in the blockchain itself using the message parameter of create_transaction() or send():

>>> key.send(..., message='Simplicity level is over 9000!!!')

Messages will be encoded as UTF-8 when stored. Also, do note that the length of each datum must not exceed 40 bytes. Therefore, your resulting byte string will be stored in chunks to adhere to this property if it is too long.

Services Timeout

If you want to change the default timeout of 5 seconds for service API calls:

>>> from bitcoinpython import set_service_timeout
>>> set_service_timeout(3)

Cache Times

If you want to change the default cache time of exchange rates (60 seconds) or recommended fees (10 minutes):

>>> from bitcoinpython import set_fee_cache_time, set_rate_cache_time
>>> set_rate_cache_time(30)
>>> set_fee_cache_time(60 * 5)

Hex to WIF

If you store your keys as hex instead of WIF you lose the ability to retain metadata. To convert your hex keys to WIF to use certain properties, do this:

>>> from bitcoinpython import Key
>>> from bitcoinpython.format import hex_to_wif
>>> # Compressed by default
>>> key1 = Key()
>>> wif = hex_to_wif(key1.to_hex(), compressed=False)
>>> key2 = Key(wif)
>>> # Same point on curve
>>> key1 == key2
>>> # Different public keys for derivation of address
>>> key1.address
>>> key2.address