richardkiss / pycoin

Python-based Bitcoin and alt-coin utility library.
MIT License
1.4k stars 497 forks source link

how to create addresses from pubkey ? #371

Open mamumi opened 4 years ago

mamumi commented 4 years ago

`

(base) C:\Users\MM>ku 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a

input : >04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5\ 1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a network : Bitcoin mainnet symbol : BTC public pair x : 89565891926547004231252920425935692360644145829622209833684329913297188986597 public pair y : 12158399299693830322967808612713398636155367887041628176798871954788371653930 x as hex : c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 y as hex : 1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a y parity : even key pair as sec : 02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 uncompressed : 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5\ 1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a hash160 : 06afd46bcdfd22ef94ac122aa11f241244a37ecc uncompressed : d6c8e828c1eca1bba065e1b83e1dc2a36e387a42 Bitcoin address : 1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP Bitcoin address uncompressed : 1LagHJk2FyCV2VzrNHVqg3gYG4TSYwDV4m Bitcoin segwit address : bc1qq6hag67dl53wl99vzg42z8eyzfz2xlkvxechjp p2sh segwit : 3FWHHE3RVgyv5vYmMrcoRdA25uugWvQbso corresponding p2sh script : 001406afd46bcdfd22ef94ac122aa11f241244a37ecc


(base) C:\Users\MM>python Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.

from pycoin.encoding.hexbytes import h2b from pycoin.symbols.btc import network pub = '04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a' hpub = h2b(pub) key = network.keys.public(hpub) key

key.address() '1LagHJk2FyCV2VzrNHVqg3gYG4TSYwDV4m' `

hello i am new on python, i know it how to create Bitcoin address , p2sh segwit and Bitcoin segwit address on python console ?

psqnt commented 4 years ago

Once you have your xprv or xpub from ku create you can generate child nodes from that, each node has an associated address.

$ ku create
$ ku <your-xpub-here> -s 0/0-10

This will generate 10 subkeys (using -s). If you are only interested in new addresses add the -a parameter to the end:

ku <xpub> -s 0/0-10 -a