Code Monkey home page Code Monkey logo

bit's Introduction

Bit: Bitcoin made easy.

image

image

image

image

image


Bit is Python's fastest Bitcoin library and was designed from the beginning to feel intuitive, be effortless to use, and have readable source code. It is heavily inspired by Requests and Keras.

Bit is so easy to use, in fact, you can do this:

>>> from bit import Key
>>>
>>> my_key = Key(...)
>>> my_key.get_balance('usd')
'12.51'
>>>
>>> # Let's donate!
>>> outputs = [
>>>     # Wikileaks
>>>     ('1HB5XMLmzFVj8ALj6mfBsbifRoD4miY36v', 0.0035, 'btc'),
>>>     # Internet Archive
>>>     ('1Archive1n2C579dMsAu3iC6tWzuQJz8dN', 190, 'jpy'),
>>>     # The Pirate Bay
>>>     ('129TQVAroeehD9fZpzK51NdZGQT4TqifbG', 3, 'eur'),
>>>     # xkcd
>>>     ('14Tr4HaKkKuC1Lmpr2YMAuYVZRWqAdRTcr', 2.5, 'cad')
>>> ]
>>>
>>> my_key.send(outputs)
'9f59f5c6757ec46fdc7440acbeb3920e614c8d1d247ac174eb6781b832710c1c'

Here is the transaction https://blockchain.info/tx/9f59f5c6757ec46fdc7440acbeb3920e614c8d1d247ac174eb6781b832710c1c.

Features

  • Python's fastest available implementation (100x faster than closest library)
  • Seamless integration with existing server setups
  • Supports keys in cold storage
  • Fully supports 25 different currencies
  • First class support for storing data in the blockchain
  • Deterministic signatures via RFC 6979
  • Access to the blockchain (and testnet chain) through multiple APIs for redundancy
  • Exchange rate API, with optional caching
  • Optimal transaction fee API, with optional caching
  • Compressed public keys by default
  • Multiple representations of private keys; WIF, PEM, DER, etc.
  • Legacy P2PKH and Segwit nested-P2WPKH transactions
  • Legacy P2SH and Segwit nested-P2WSH transactions

If you are intrigued, continue reading. If not, continue all the same!

Installation

Bit is distributed on PyPI as a universal wheel and is available on Linux/macOS and Windows and supports Python 3.5+ and PyPy3.5-v5.7.1+. pip >= 8.1.2 is required.

$ pip install bit

Documentation

Docs are hosted by Github Pages and are automatically built and published by Travis after every successful commit to Bit's master branch.

Credits

bit's People

Contributors

b-kelly avatar bjarnemagnussen avatar chikko80 avatar christianoconnor avatar eazyserver avatar gauthamramravichandran avatar mgaitan avatar natenate60 avatar ofek avatar pedr0-fr avatar philsippl avatar qxe5 avatar visveshkhanna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bit's Issues

Implement BIP143 support?

Required for #9 and might be a good step forward. You seem to already use compressed addresses by default.

Is this something you're interseted in doing? I'm already in way over my head trying to add Bitcoin Cash support to walkingliberty. pybitcoin doesn't have compressed public addresses nor BIP-143. electrum has BIP-143 but using that codebase looks like a nightmare.

Thank you!

Error:"import pycurl # type: ignore ImportError:..." when running pyspider all

When I run "pyspider all", it occurs error as following:
~$ pyspider all
Error: Could not create web server listening on port 25555
Error: Could not create web server listening on port 25555
[I 190119 13:25:24 result_worker:49] result_worker starting...
[I 190119 13:25:25 processor:211] processor starting...
Process Process-4:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pyspider/run.py", line 236, in fetcher
Fetcher = load_cls(None, None, fetcher_cls)
File "/usr/local/lib/python3.7/site-packages/pyspider/run.py", line 48, in load_cls
return utils.load_object(value)
File "/usr/local/lib/python3.7/site-packages/pyspider/libs/utils.py", line 369, in load_object
module = import(module_name, globals(), locals(), [object_name])
File "/usr/local/lib/python3.7/site-packages/pyspider/fetcher/init.py", line 1, in
from .tornado_fetcher import Fetcher
File "/usr/local/lib/python3.7/site-packages/pyspider/fetcher/tornado_fetcher.py", line 30, in
from tornado.curl_httpclient import Curlasync_modeHTTPClient
File "/usr/local/lib/python3.7/site-packages/tornado/curl_httpclient.py", line 24, in
import pycurl # type: ignore
ImportError: dlopen(/usr/local/lib/python3.7/site-packages/pycurl.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libcrypto.1.1.dylib
Referenced from: /usr/local/lib/python3.7/site-packages/pycurl.cpython-37m-darwin.so
Reason: image not found
[I 190119 13:25:25 scheduler:647] scheduler starting...
Traceback (most recent call last):
File "/usr/local/bin/pyspider", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/pyspider/run.py", line 754, in main
cli()
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pyspider/run.py", line 497, in all
ctx.invoke(webui, **webui_config)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pyspider/run.py", line 333, in webui
app = load_cls(None, None, webui_instance)
File "/usr/local/lib/python3.7/site-packages/pyspider/run.py", line 48, in load_cls
return utils.load_object(value)
File "/usr/local/lib/python3.7/site-packages/pyspider/libs/utils.py", line 369, in load_object
module = import(module_name, globals(), locals(), [object_name])
File "/usr/local/lib/python3.7/site-packages/pyspider/webui/init.py", line 8, in
from . import app, index, debug, task, result, login
File "/usr/local/lib/python3.7/site-packages/pyspider/webui/app.py", line 17, in
from pyspider.fetcher import tornado_fetcher
File "/usr/local/lib/python3.7/site-packages/pyspider/fetcher/init.py", line 1, in
from .tornado_fetcher import Fetcher
File "/usr/local/lib/python3.7/site-packages/pyspider/fetcher/tornado_fetcher.py", line 30, in
from tornado.curl_httpclient import Curlasync_modeHTTPClient
File "/usr/local/lib/python3.7/site-packages/tornado/curl_httpclient.py", line 24, in
import pycurl # type: ignore
ImportError: dlopen(/usr/local/lib/python3.7/site-packages/pycurl.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libcrypto.1.1.dylib
Referenced from: /usr/local/lib/python3.7/site-packages/pycurl.cpython-37m-darwin.so
Reason: image not found

Please help.

Starting Bit error: ImportError

Hi, I am using Python3.6, and am having trouble starting with bit. I am running 3.6 inside a virtualenv, but get the following error:

from bit import *
Traceback (most recent call last):
File "", line 1, in
File "/Users/.../lib/python3.6/site-packages/bit/init.py", line 1, in
from bit.format import verify_sig
File "/Users/.../lib/python3.6/site-packages/bit/format.py", line 1, in
from coincurve import verify_signature as _vs
File "/Users/.../lib/python3.6/site-packages/coincurve/init.py", line 1, in
from coincurve.context import GLOBAL_CONTEXT, Context
File "/Users/.../lib/python3.6/site-packages/coincurve/context.py", line 4, in
from coincurve.flags import CONTEXT_ALL, CONTEXT_FLAGS
File "/Users/.../lib/python3.6/site-packages/coincurve/flags.py", line 1, in
from ._libsecp256k1 import lib
ImportError: dlopen(/Users/.../lib/python3.6/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
Referenced from: /Users/.../lib/python3.6/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so
Reason: image not found

I have checked that my path, and that i'm running python3.6:

print(sys.path)
['', '/Users/.../lib/python36.zip', '/Users/.../lib/python3.6', '/Users/.../lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Users/.../lib/python3.6/site-packages']

Any help would be appreciated!

the only issue

the only issue anyone can have with this library is that it's not available for ethereum yet ;)

[Error] send btc with testnet

wifi_key_from = "cNTgUJtZYxK4iC2wDxLxSityGtqWyDLUnJbg2ESWgmUZ63z6eFzG"
address_from = "motaaTUVLRTSVXQo9RUMTxJEX6BACZ8WGo"
to_address = "mvsPR91C29sQzoXiAJaod8s1XneMJKYB6U"
to_wifi = "cNGfoMaD7Aer7mUpDch8KWwMv4yqZLQT318DaWzYLQTQij8Bw1ct"

from bit import Key, PrivateKey, PrivateKeyTestnet

my_key = PrivateKeyTestnet(wifi_key_from)
print(my_key.address)
print(my_key.get_balance('btc'))

to_add = PrivateKeyTestnet(to_wifi)
print(to_add.address)
print(to_add.get_balance('btc'))

outputs = [
(to_add, 0.0001, 'btc')
]

# print(my_key.get_unspents())
tx = my_key.send(outputs)
print(tx)
motaaTUVLRTSVXQo9RUMTxJEX6BACZ8WGo
0.09786592
mvsPR91C29sQzoXiAJaod8s1XneMJKYB6U
0
Traceback (most recent call last):
  File "/home/tomtony/sourcecode/fx001/backend/TestH7.py", line 24, in <module>
    tx = my_key.send(outputs)
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/wallet.py", line 722, in send
    unspents=unspents
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/wallet.py", line 674, in create_transaction
    version=self.version
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/transaction.py", line 446, in sanitize_tx_data
    output_size = [len(address_to_scriptpubkey(o[0])) + 9 for o in outputs]
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/transaction.py", line 446, in <listcomp>
    output_size = [len(address_to_scriptpubkey(o[0])) + 9 for o in outputs]
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/transaction.py", line 476, in address_to_scriptpubkey
    get_version(address)
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/format.py", line 38, in get_version
    version, _ = bech32_decode(address)
  File "/home/tomtony/python_env/fx-env/lib/python3.6/site-packages/bit/base32.py", line 63, in bech32_decode
    if ((any(ord(x) < 33 or ord(x) > 126 for x in bech)) or
TypeError: 'PrivateKeyTestnet' object is not iterable

Process finished with exit code 1

Generate addresses

Hello,

I need to create addresses on HD wallet. How can I do it?

Best regards

I can't import pem key

I'm trying to import a pem key:

key = """-----BEGIN PRIVATE KEY-----
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAxY6A0TAXwBeQ+k+L
JB4bgJWvWV4U0hTyryJA6+g7VVC26WN4VDNkSC4xuL0DA7c+kTNst2i5qSbYVgrk
RCo7iwIDAQABAkEAxB5nu0NnEIdUoWl90+kfnFL8tFc1jCjHkx0KHid5X4L2X7Ya
g62bbj3BBqId1vUUBltALN5h2PBCGvvuFYDooQIhAOsVaZUAw0KXijKeQV4Q5Xs5
erhPMFQIhqc/bff0gMrnAiEA1yJTFvWppYXrYI9NtxNzhSCa8oujsmwYaZRoyk8B
Ob0CIEnyX1beeY1N68vGWhuDxxu+1ep6BmK4l9quKiJQB99LAiAHZijRa1WQWdDE
m2ki2MpqU7rAiMjyhAE68F3CR4FVSQIgIggFS94m33R+n4mA25lJGyGRnV5iiynN
DLyEyGqhZOY=
-----END PRIVATE KEY-----"""
``
key_obj = Key.from_pem( key )

But what I get is:

Traceback (most recent call last): File "main.py", line 28, in <module> key_obj = Key.from_pem( key ) File "/home/silvio/Sviluppo/vest/vendor/code_manager/code_manager/lib/python3.6/site-packages/bit/wallet.py", line 392, in from_pem return PrivateKey(ECPrivateKey.from_pem(pem)) File "/home/silvio/Sviluppo/vest/vendor/code_manager/code_manager/lib/python3.6/site-packages/coincurve/keys.py", line 159, in from_pem pem_to_der(pem) File "/home/silvio/Sviluppo/vest/vendor/code_manager/code_manager/lib/python3.6/site-packages/coincurve/utils.py", line 90, in pem_to_der pem.strip()[28:-25].replace(b'\n', b'') TypeError: replace() argument 1 must be str, not bytes

So I tried:

key = b"""-----BEGIN PRIVATE KEY-----
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAxY6A0TAXwBeQ+k+L
JB4bgJWvWV4U0hTyryJA6+g7VVC26WN4VDNkSC4xuL0DA7c+kTNst2i5qSbYVgrk
RCo7iwIDAQABAkEAxB5nu0NnEIdUoWl90+kfnFL8tFc1jCjHkx0KHid5X4L2X7Ya
g62bbj3BBqId1vUUBltALN5h2PBCGvvuFYDooQIhAOsVaZUAw0KXijKeQV4Q5Xs5
erhPMFQIhqc/bff0gMrnAiEA1yJTFvWppYXrYI9NtxNzhSCa8oujsmwYaZRoyk8B
Ob0CIEnyX1beeY1N68vGWhuDxxu+1ep6BmK4l9quKiJQB99LAiAHZijRa1WQWdDE
m2ki2MpqU7rAiMjyhAE68F3CR4FVSQIgIggFS94m33R+n4mA25lJGyGRnV5iiynN
DLyEyGqhZOY=
-----END PRIVATE KEY-----"""
``
key_obj = Key.from_pem( key )

But what I get is:

Traceback (most recent call last): File "main.py", line 28, in <module> key_obj = Key.from_pem( key ) File "/home/silvio/Sviluppo/vest/vendor/code_manager/code_manager/lib/python3.6/site-packages/bit/wallet.py", line 392, in from_pem return PrivateKey(ECPrivateKey.from_pem(pem)) File "/home/silvio/Sviluppo/vest/vendor/code_manager/code_manager/lib/python3.6/site-packages/coincurve/keys.py", line 160, in from_pem ).native['private_key']['private_key']), KeyError: 'private_key'

Your docs say:

classmethod from_pem(pem)
Parameters: pemย (bytes) โ€“ A private key previously encoded as PEM.
Return type: PrivateKey

So I tried:

key = """-----BEGIN PRIVATE KEY-----
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAxY6A0TAXwBeQ+k+L
JB4bgJWvWV4U0hTyryJA6+g7VVC26WN4VDNkSC4xuL0DA7c+kTNst2i5qSbYVgrk
RCo7iwIDAQABAkEAxB5nu0NnEIdUoWl90+kfnFL8tFc1jCjHkx0KHid5X4L2X7Ya
g62bbj3BBqId1vUUBltALN5h2PBCGvvuFYDooQIhAOsVaZUAw0KXijKeQV4Q5Xs5
erhPMFQIhqc/bff0gMrnAiEA1yJTFvWppYXrYI9NtxNzhSCa8oujsmwYaZRoyk8B
Ob0CIEnyX1beeY1N68vGWhuDxxu+1ep6BmK4l9quKiJQB99LAiAHZijRa1WQWdDE
m2ki2MpqU7rAiMjyhAE68F3CR4FVSQIgIggFS94m33R+n4mA25lJGyGRnV5iiynN
DLyEyGqhZOY=
-----END PRIVATE KEY-----"""
``
key_obj = Key.from_pem( bytes(key, 'utf-8') )

But the risult is the same.
Any help?

Thank you

Testnet transfers fail when there are clearly unspents available

Hi,

Great library, thanks for building it!

I was able to get to speed rather quickly and could move testnet coins around but I noticed that very often I have to wait a while for create_transaction() or send() to return without errors. In some cases I had 8 confirmations on a testnet wallet after getting some coins from a faucet and trying to move them to destinations also generated by this same library. The error I usually hit :

~/anaconda2/envs/foo/lib/python3.6/site-packages/bit/transaction.py in sanitize_tx_data(unspents, outputs, fee, leftover, combine, message, compressed)
     93 
     94     if not unspents:
---> 95         raise ValueError('Transactions must have at least one unspent.')
     96 

However calling get_unspents() clearly shows Unspents and confirmations. What's the reason for this error?

Uncompressed public keys

Hello
I need to create uncompressed public keys whith text.
For compressed Keys i use:
key = Key.from_int(int(sh.sha256(word.encode('utf-8')).hexdigest(),16))
wif = key.to_wif()
addr= key.address
works fine, but i need the same with uncompressed.
It's possible ??

Generate address with text

Hello.
Is possible to generate address with text ?
for exemple:

k = Key('Hello this is my text')
print(k.address)

Building blocks for Replace By Fee

I have a transaction stuck in pergatory that'll never confirm, yet never seems to get out of mempool.

I'd like to sweep that wallet, but (most) of the APIs don't return those unspents. I've been thinking about how to do a Replace By Fee transaction. I figure you just take the inputs of the transaction you want, then adjust the outputs/fee accordingly and broadcast that transaction.

So to do this I think we need:

get_transaction() to get the hex of a transaction broadcast. We then need get_transaction_as_unspent() which would take the hex of a transaction and return it as an unspent. I guess a second argument would be the key, unless we just provide that in the key class that this is off of anyways.

Then finally, get_unspents_from_transaction() which would iterate through the inputs of a transaction, and build an unspent list that could then be used by send().

Does that seem about right? Not sure I want to add this in any time soon but I am curious if this seems about like the right approach.

So it'd look kind of like:

key.send(unspents=key.get_unspents_from_transaction('rbftransactionid')...)

Thanks!

Why is combine=False not the default?

Hi ofek and all,

This is by far the nicest Python Bitcoin library I've looked at.

Just curious about your rationale for setting combine as True by default. I would think that a user will never pay lower fees with combine as True and may end up paying higher.

Let's say there are six inputs of 10,000 Satoshis each. The user will make two transactions of 11,000 Satoshis.

If combined is True:

Transaction 1 takes 6 inputs for the transaction and has two outputs.

Transaction 2 takes 1 input for the transaction and has two outputs.

If combined is False:

Transaction 1 takes 2 inputs for the transaction and has two outputs.

Transaction 2 takes 2 inputs for the transaction and has two outputs.

At this point, the transaction size has been 7 inputs vs 4 inputs. combine=True logic is definitely simpler to implement, but once combine=False logic is implemented I don't see a reason to use combine=True. You can do some really clever stuff if expanding on combine=False, like matching inputs exactly if you have that opportunity, or building up the smallest possible transactions. I think in general the smaller transactions will consume the dust-like inputs which would otherwise be needlessly combined if combine=True. In the end the user will pay transaction fees now or later. It might make sense to do combine=True when mempool is abnormally low, but other than that optimization I think you can never do worse with combine=False and occasionally better.

Please correct me if I'm wrong on this. I think a lot of unspent selection nuances are ignored and are likely worthy of consideration, especially with TX fees as high as they are in BTC.

Thank you!

-Teran

How do you generate a public address?

I'm not sure where else to ask, but I can't seem to generate a public address(for sending transactions).
According to your wiki after generating a private key via key = Key() I should be able to use the address attribute. but key.address give back the private key again and key.public_key generates something unusable (at least by a novice).

What am I doing wrong?

Sweeping funds from multiple addresses to a single address

I needed to sweep funds from multiple addresses I own (i.e. I have their private keys) to a single address. I did not find a way to do that from the documentation so I added that functionality in my fork.

Here's a reference to my commit:
joemarct@42450a5

Usage is as follows:

from bit import PrivateKey
from bit.transaction import create_sweep_transaction
from bit.network import NetworkAPI

# Generate addresses (or import private keys)
key1 = PrivateKey()
key2 = PrivateKey()
key3 = PrivateKey()

# Sweep the funds of key1, key2 and key3 to the destination address below
destination = 'n1n2YUzwJSNueBsKE6D9kaQGrLFj3Wc3bL'
sweep_tx = create_sweep_transaction([key1, key2, key3], destination)

# Broadcast the transaction
NetworkAPI.broadcast_tx_testnet(sweep_tx)

If there is interest in having this merged here, I'll create a pull request.

ImportError: Library not loaded: Reason: image not found

I have tried running a simple code to check my testnet balance, but it isn't working.
Here is my code:
screen shot 2018-07-02 at 4 09 37 pm

I when i run "python BTCt.py" or "python3 BTC.py" the following error is thrown:

Traceback (most recent call last):
File "BTCt.py", line 1, in
from bit.network.services import SmartBitAPI
File "/Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/bit/init.py", line 1, in
from bit.format import verify_sig
File "/Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/bit/format.py", line 1, in
from coincurve import verify_signature as _vs
File "/Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/coincurve/init.py", line 1, in
from coincurve.context import GLOBAL_CONTEXT, Context
File "/Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/coincurve/context.py", line 4, in
from coincurve.flags import CONTEXT_ALL, CONTEXT_FLAGS
File "/Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/coincurve/flags.py", line 1, in
from ._libsecp256k1 import lib
ImportError: dlopen(/Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
Referenced from: /Users/MannyKuflik/Library/Python/3.6/lib/python/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so
Reason: image not found

Please help

Questions about balance

Hello

How is the get_balance informatin retrieved? Is it getting from blobkchain.info? Is there a limit on how many times in a row you can use it?
It has returned 0 satoshis on the private keys I tried even when the computer was disconnected from the network.
Also, is it possible to get the balance of a public key/address instead of a private key?

Thanks

MultiSig naming suggestion

Fantastic repo. When I first used this, I was confused by the naming of MultiSig. I assumed the class was a MultiSig wallet, but it actually represents a single member of the MultiSig wallet right?

Would you consider a PR renaming it to MultiSigMember, or can you think of a better name?

speed in idle

Why speed of execution in console $ python -m timeit -s "from bit import Key;k=Key()" "k.address" faster than in IDLE? In IDLE 100000 take 10 sec.

from bit import Key

start_time = time.time()

i = 100000
while i >= 1:

k=Key()
k.address

i = i -1

print("--- %s seconds ---" % (time.time() - start_time))

estimate_tx_fee() not working correctly for multisig

The function estimate_tx_fee() was not edited accordingly to allow correct fee estimation for multisig keys. I just published a pull request for segwit functionality and the same holds true for segwit.

Maybe someone has any good ideas to allow estimate_tx_fee to calculate a correct fee. I will also try to work on it in the near future.

ImportError: No module named 'coincurve'

When I go to run a program based on this, I get:
Traceback (most recent call last):
File "C:\Users*\Desktop\bit-master\bitcoin2.py", line 1, in
from bit import Key
File "C:\Users*
\Desktop\bit-master\bit_init_.py", line 1, in
from bit.format import verify_sig
File "C:\Users***\Desktop\bit-master\bit\format.py", line 2, in
from coincurve import *
ImportError: No module named 'coincurve'

The problem is I imported coincurve directly into my folder as well as installing it with pip. Further I tried to look for verify_sig anywhere and could not find it.

Local node support

Hi,

This seems to be the only sanest python bitcoin library. Truely, great work there.

I would love to use this library but unfortunately local nodes are not supported.

Do you have any timeline to support the local nodes?

Do you need funding or donation?

Please, let me know.

Class MultiSig creates different contracts depending on the ordering of public keys

Currently the MultiSig class behaves like the raw Bitcoin protocol by creating a multisignature contract ordering the public keys in the Script exactly as they were used as arguments in the initialization of MultiSig.

For Bit I think it would make much more sense to use lexicographical ordering of the public keys, so that it does not matter in which order the public keys are presented when initializing the MultiSig class (see answer to https://bitcoin.stackexchange.com/questions/39370/how-to-create-the-same-2-of-3-multisig-adresses-as-electrums-multisig-wallets).

I regret not having thought of that from the beginning. Following the implementation of P2SH multisignature, Bit has grown to a new release number and forcing lexicographical ordering may break currently used multisignature contracts created with the class MultiSig.

For simplicity of use in Bit I suggest to change the default behaviour to use lexicographical ordering, but allowing a flag to be set that disables this ordering. A code change to allow for this would be quite straight forward.

Are there any reasons against it?

Pay to scripthash

I have no experience with paying to scripthashes except when it's worked automagically for me before.

In #12 it looks like the initial workins of P2SH are being added. I'm not sure how straight forward P2SH is.

But... for the time being shouldn't we throw an exception if we try to send() to an address that does not begin with 1? Are there any sideeffects to doing so?

I think I just lost a fair bit of coin not reviewing this properly. Hopefully if we add in an exception we can keep others from doing the same.

Key object with brainwallet? [Question]

The documentation here mentions from_hex and a way to import from WIF. But is there a way to import a key from a brainwallet? e.g. correct horse battery staple? I've just taken a quick glance at the docs and was wondering if this is possible.

Testnet wallet is drained

Currently the testnet wallet WALLET_FORMAT_TEST is drained (see last Travis build report). Since we return testnet coins to the address n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi belonging to the faucet tpfaucet.appspot.com, I wanted to request new testnet coins from them.

However it appears that the faucet is offline (the captcha hasn't been working for some time). So maybe we should switch to another faucet and also use that new faucet's address to return testnet coins?

Get unexpected receiver address when creating transaction

When calling k.create_transaction([('2N2ud4TqixtLTf4cpEsJTdUb1TZegQUkB2U', 2,'btc')]), the output result in generated decoded transaction is

    "inputs": [
        {
            "addresses": [
                "mwRCvxvDWoHfLoXbu4CRsSr8n9DJCVPboK"
            ], 
            "age": 1202275, 
            "output_index": 1, 
            "output_value": 456995984, 
            "prev_hash": "50dcac87356e68d6b43c0f24ca8dc98e3458c762077ae29a2d660f9aaa50ccb5", 
            "script": "47304402201314fa5216a64079c5196be75fa94280f2c4a91f4181d75a659877473b4c3bd102204fa04af563ab56af0b7e8aea5bf6b1e12f409daa3582f60c208cd856ffef76b6012102ecfde94a36fcf549283ae65c379feb7c63df59edd3a1a0f96816d1ddbc17f690", 
            "script_type": "pay-to-pubkey-hash", 
            "sequence": 4294967295
        }
    ], 
    "outputs": [
        {
            "addresses": [
                "mqBMNEWEcYwz9DmTACzNQpT8xgkVyoxXBK"
            ], 
            "script": "76a91469fc32bc91d99f6d5710838824eef70ed6fb207d88ac", 
            "script_type": "pay-to-pubkey-hash", 
            "value": 200000000
        }, 
        {
            "addresses": [
                "mwRCvxvDWoHfLoXbu4CRsSr8n9DJCVPboK"
            ], 
            "script": "76a914ae6bbc0fd6d934269238fc869cc04ac775fded9888ac", 
            "script_type": "pay-to-pubkey-hash", 
            "value": 256959824
        }
    ]

The address mwRCvxvDWoHfLoXbu4CRsSr8n9DJCVPboK is the sender, and the receiver becomes mqBMNEWEcYwz9DmTACzNQpT8xgkVyoxXBK instead of 2N2ud4TqixtLTf4cpEsJTdUb1TZegQUkB2U, why it happens?

Multisig error

What's wrong with that? The code below gives out an error Traceback (most recent call last): File "/home/tony/Documents/DLF/Dev/1.py", line 15, in <module> NetworkAPI.broadcast_tx_testnet(tx_2) File "/home/tony/.local/lib/python3.7/site-packages/bit/network/services.py", line 533, in broadcast_tx_testnet raise ConnectionError('Transaction broadcast failed, or ' ConnectionError: Transaction broadcast failed, or Unspents were already used

Balance = 0.04 BTC

from bit import MultiSigTestnet, PrivateKeyTestnet, wif_to_key
from bit.network import NetworkAPI

key1 = wif_to_key(WIF1)
key2 = wif_to_key(WIF2)

multisig1 = MultiSigTestnet(key1, {key1.public_key, key2.public_key}, 2)
multisig2 = MultiSigTestnet(key2, {key1.public_key, key2.public_key}, 2)
tx_1 = multisig1.create_transaction([('2Mxpa7jzh37ZuXKVxqnS5RLD7XCdGFrDFy1', 100000, 'satoshi')], fee=30)
tx_2 = multisig2.sign_transaction(tx_1) 
print(tx_1, tx_2)
NetworkAPI.broadcast_tx_testnet(tx_2)



Address Balance Query

I'm having issues with the Code Sample from the Documentation on balance requests.

Why does the code sample use the Testnet to get a balance of a wallet. Is there a "Mainnet" function to access the balance? I assume that the Testnet doesn't provide accurate transactions from the Blockchain, am I wrong?

Also is there a way to get the balance of an address without knowing the private key, which is also used in the code sample. Many other libraries use the wallet address as the argument to a getBalance function. Does Bit have something similar?

Code Sample In Question: key = PrivateKeyTestnet('cU6s7jckL3bZUUkb3Q2CD9vNu8F1o58K5R5a3JFtidoccMbhEGKZ')

Thanks in advance

Mixing mainnet and testnet addresses in outputs

Bitcoin mainnet and testnet addresses encode the same information/scripts, but have different prefixes to differentiate between the two networks.

Currently in Bit it is possible to e.g. spend from a mainnet address/PrivateKey but include testnet addresses in the outputs (and vice versa, and mixed cases). Bit then simply converts those testnet addresses to its mainnet equivalent in the outputs of the spending transaction.

This may lead to confusion, and I would like to discuss if maybe there should be some sanity checks in place to let the user know when a mix of mainnet and testnet addresses and private keys are used?

TypeError: string indices must be integers

Hi,

Just to test your lib and how it s handle error and refuse from service use to get balance, i just executed the following code, once you reach quota limit of services API the error appear.

>>> import bit
>>> while True:
...   k = bit.Key()
...   if k.get_balance() != '0':
...     print(k.to_wif())
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/local/lib/python3.5/dist-packages/bit/wallet.py", line 190, in get_balance
    self.get_unspents()
  File "/usr/local/lib/python3.5/dist-packages/bit/wallet.py", line 198, in get_unspents
    self.unspents[:] = NetworkAPI.get_unspent(self.address)
  File "/usr/local/lib/python3.5/dist-packages/bit/network/services.py", line 421, in get_unspent
    return api_call(address)
  File "/usr/local/lib/python3.5/dist-packages/bit/network/services.py", line 41, in get_unspent
    for tx in r.json()
  File "/usr/local/lib/python3.5/dist-packages/bit/network/services.py", line 41, in <listcomp>
    for tx in r.json()
TypeError: string indices must be integers```

How to specify exact fee and send all the bitcoins to another address?

Thanks for developing this amazing project.

I have 8250 satoshis on Testnet, and when I invoke key.send() and specify the fee, it raised an error, because the fee parameter is satoshis/byte, not just fee itself.

How can I specify the fee and send all the bitcoins to another address?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.