Bitcoin Forum

Bitcoin => Project Development => Topic started by: xcbtrader on November 26, 2016, 07:49:08 PM



Title: Create bitcoin address with python
Post by: xcbtrader on November 26, 2016, 07:49:08 PM
Hello.

Im searching python bitcoin library to create speed bitcoin address (public, private and wif) like:

https://github.com/vbuterin/pybitcointools (https://github.com/vbuterin/pybitcointools)

And example of code:

Code:
from bitcoin import *

def create_addr():
priv = random_key()
pub = privtopub(priv)
addr = pubtoaddr(pub)
        electrumPKey = encode_privkey(priv, 'wif')
return addr, priv, electrumPKey

addr,priv,electrumPKey = create_addr()


Another code?

Thanks


Title: Re: Create bitcoin address with python
Post by: btc_enigma on November 28, 2016, 04:01:46 AM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md


Title: Re: Create bitcoin address with python
Post by: xcbtrader on November 28, 2016, 09:52:05 AM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md

I know this library, but I do not know how to do the same with it.


Title: Re: Create bitcoin address with python
Post by: xcbtrader on November 28, 2016, 12:02:05 PM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md

I know this library, but I do not know how to do the same with it.

I found this code:

Code:
import hashlib
from pycoin import ecdsa, encoding
import os
import codecs

rand = codecs.encode(os.urandom(32), 'hex').decode()
secret_exponent= int('0x'+rand, 0)
print ('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
print('Bitcoin address: %s' % encoding.hash160_sec_to_bitcoin_address(hash160))


Title: Re: Create bitcoin address with python
Post by: btc_enigma on November 28, 2016, 12:09:20 PM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md

I know this library, but I do not know how to do the same with it.

I found this code:

Code:
import hashlib
from pycoin import ecdsa, encoding
import os
import codecs

rand = codecs.encode(os.urandom(32), 'hex').decode()
secret_exponent= int('0x'+rand, 0)
print ('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
print('Bitcoin address: %s' % encoding.hash160_sec_to_bitcoin_address(hash160))

Awesome... works!


Title: Re: Create bitcoin address with python
Post by: btc_enigma on November 28, 2016, 01:14:45 PM
moneywagon (https://github.com/priestc/moneywagon)  also can do this for you

Code:
from moneywagon import generate_keypair
print generate_keypair('btc', 'randomtextwithentropy')
Internally uses https://github.com/petertodd/python-bitcoinlib library.
The Swiss Army Knife of the Bitcoin protocol." - Wladimir J. van der Laan



Title: Re: Create bitcoin address with python
Post by: xcbtrader on November 28, 2016, 02:13:25 PM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md

I know this library, but I do not know how to do the same with it.

I found this code:

Code:
import hashlib
from pycoin import ecdsa, encoding
import os
import codecs

rand = codecs.encode(os.urandom(32), 'hex').decode()
secret_exponent= int('0x'+rand, 0)
print ('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
print('Bitcoin address: %s' % encoding.hash160_sec_to_bitcoin_address(hash160))

Awesome... works!

Yes but it is much slower than the other (1/3)


Title: Re: Create bitcoin address with python
Post by: xcbtrader on November 30, 2016, 03:43:10 PM
Some faster library?


Title: Re: Create bitcoin address with python
Post by: xcbtrader on December 01, 2016, 06:41:02 AM
Any code in c++?


Title: Re: Create bitcoin address with python
Post by: btc_enigma on December 01, 2016, 06:45:29 AM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md

I know this library, but I do not know how to do the same with it.

I found this code:

Code:
import hashlib
from pycoin import ecdsa, encoding
import os
import codecs

rand = codecs.encode(os.urandom(32), 'hex').decode()
secret_exponent= int('0x'+rand, 0)
print ('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
print('Bitcoin address: %s' % encoding.hash160_sec_to_bitcoin_address(hash160))

Awesome... works!

Yes but it is much slower than the other (1/3)

Can you share me some status on much times these are taking


Title: Re: Create bitcoin address with python
Post by: xcbtrader on December 01, 2016, 07:40:25 PM
You can use pycoin as well

https://github.com/richardkiss/pycoin/blob/master/COMMAND-LINE-TOOLS.md

I know this library, but I do not know how to do the same with it.

I found this code:

Code:
import hashlib
from pycoin import ecdsa, encoding
import os
import codecs

rand = codecs.encode(os.urandom(32), 'hex').decode()
secret_exponent= int('0x'+rand, 0)
print ('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
print('Bitcoin address: %s' % encoding.hash160_sec_to_bitcoin_address(hash160))

Awesome... works!

Yes but it is much slower than the other (1/3)

Can you share me some status on much times these are taking

It's easy to check the diference:

Program 1:
Code:
from bitcoin import *
import time

def create_addr():
priv = random_key()
pub = privtopub(priv)
addr = pubtoaddr(pub)
return addr, priv

elapsed_time = time.time()
for a in range(100):
        addr,priv = create_addr()

print ('Total time = ' + str(time.time() - elapsed_time))

Program 2:

Code:
import hashlib
from pycoin import ecdsa, encoding
import os
import codecs
import time

def create_addr():
        priv = codecs.encode(os.urandom(32), 'hex').decode()
        secret_exponent= int('0x'+rand, 0)
        public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
        hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
        addr =  encoding.hash160_sec_to_bitcoin_address(hash160)
return addr, priv

elapsed_time = time.time()
for a in range(100):
        addr,priv = create_addr()

print ('Total time = ' + str(time.time() - elapsed_time))


Title: Re: Create bitcoin address with python
Post by: xcbtrader on December 09, 2016, 09:06:27 AM
I found this fast python (only python 2.7 not 3) address generator:

https://github.com/weex/addrgen (https://github.com/weex/addrgen)