Title: create bech32 address in python bit library and questions Post by: yoshimitsu777 on December 25, 2022, 08:33:44 AM i want to create bech32 address in bit.
Quote >>> from bit import Key >>> key = Key() >>> print(key) <PrivateKey: 1Q42mvgDhLYYD4hEcLbpwXNheKKUFDupxa> the output is the address not privkey.Comparison here: Quote >>> print(key.address) 1Q42mvgDhLYYD4hEcLbpwXNheKKUFDupxa Why does bit not output the privkey as expected?I have to use this command to get the privkey displayed as expected Quote >>> print(key.to_hex()) 57d706092c69dbdd7275caaf594163368d0d05af2e56aed55e48df5eeab5e6df there is a command to output tje segwit address that begins with '3' Quote >>> print(key.segwit_address) 3744W6xs6musQKTGhLYTrr3VffphdG5E8f but how do I output the bech32 address that begins with 'bc1' ? Title: Re: create bech32 address in python bit library and questions Post by: seoincorporation on December 26, 2022, 03:27:23 AM i want to create bech32 address in bit. Quote >>> from bit import Key >>> key = Key() >>> print(key) <PrivateKey: 1Q42mvgDhLYYD4hEcLbpwXNheKKUFDupxa> the output is the address not privkey.Comparison here: Quote >>> print(key.address) 1Q42mvgDhLYYD4hEcLbpwXNheKKUFDupxa Why does bit not output the privkey as expected?I have to use this command to get the privkey displayed as expected Quote >>> print(key.to_hex()) 57d706092c69dbdd7275caaf594163368d0d05af2e56aed55e48df5eeab5e6df there is a command to output tje segwit address that begins with '3' Quote >>> print(key.segwit_address) 3744W6xs6musQKTGhLYTrr3VffphdG5E8f but how do I output the bech32 address that begins with 'bc1' ? the only way I know to do that with python is by getting the hash160 from the address, and then get the bench32 address from the hash160 Code: >>> import binascii, hashlib, base58 So, now we have the hash160 we get the bench32 address: Code: >>> import bech32 And to prove the data is right, you can verify it in the next link: https://privatekeys.pw/address/bitcoin/1Q42mvgDhLYYD4hEcLbpwXNheKKUFDupxa I hope these commands help you because as AlexanderCurl mentioned, it isn't possible to do it directly from bit library. Title: Re: create bech32 address in python bit library and questions Post by: witcher_sense on December 26, 2022, 04:55:14 AM I haven't found a way to generate a native SegWit address directly from 'user Interface', but you certainly can create it using internal functionality of this library. All the necessary functions for proper bech32 encoding are present there.
The following piece of code that I come up with works as intended: Code: import bit Title: Re: create bech32 address in python bit library and questions Post by: yoshimitsu777 on January 02, 2023, 09:39:54 AM thank you witcher_sense
Title: Re: create bech32 address in python bit library and questions Post by: larry_vw_1955 on January 03, 2023, 04:03:12 AM I haven't found a way to generate a native SegWit address directly from 'user Interface', but you certainly can create it using internal functionality of this library. All the necessary functions for proper bech32 encoding are present there. The following piece of code that I come up with works as intended: Code: import bit How's the performance vs generating legacy addresses? I would expect it to be significantly lower but I guess that's something to test out. :o When I say performance, I mean like generating 1 million addresses, how fast can it do it... Title: Re: create bech32 address in python bit library and questions Post by: witcher_sense on January 03, 2023, 05:46:37 AM How's the performance vs generating legacy addresses? I would expect it to be significantly lower but I guess that's something to test out. :o When I say performance, I mean like generating 1 million addresses, how fast can it do it... I haven't measured the performance (Legacy vs Native SegWit), but I also think that generation of bech32 addresses is more costly in terms of system resources than that of legacy addresses. Anyway, this approach is not suitable for the fast generation of addresses because in order to calculate a million of bitcoin addresses, you need to create the same number of instances of PrivateKey class, which is an extremely inefficient way and consumes too much computer memory. And after conducting a small test where I try to calculate just 10000 addresses without printing them or writing them to a file, I can conclude that it is a very slow method. Here is the result:Code: $ time python test_bit.py Title: Re: create bech32 address in python bit library and questions Post by: larry_vw_1955 on January 03, 2023, 11:43:02 PM Anyway, this approach is not suitable for the fast generation of addresses because in order to calculate a million of bitcoin addresses, you need to create the same number of instances of PrivateKey class, which is an extremely inefficient way and consumes too much computer memory. you don't have to store them you just have to store one at a time. so there are no memory requirements.Quote And after conducting a small test where I try to calculate just 10000 addresses without printing them or writing them to a file, I can conclude that it is a very slow method. what's faster?Quote It took more than 4 seconds on my laptop to perform 10000 calculations (private-public-address). how long does it take your laptop to generate 10000 legacy addresses? in my small test, I find that generating legacy addresses using the bit package is about twice as fast as generating bech32 ones. Code: Number of addresses processed: Uncompressed addresses only followed a similar time. So I'd say based on this I'd say that if bit is considered fast and efficient method of generating legacy addresses, then it probably is about the fastest way for bech32 also. and if what you say is true that bech32 is more cpu intensive then you probably can't do any better. Title: Re: create bech32 address in python bit library and questions Post by: witcher_sense on January 04, 2023, 06:36:12 AM you don't have to store them you just have to store one at a time. so there are no memory requirements. You're right, I guess. In my initial solution, I created a for loop with required number of iterations and was reassigning a calculated result to the same variable 'address'. So, I never stored more than one address in memory.Quote what's faster? You should probably check this (https://bitcointalk.org/index.php?topic=5432068.0) thread where guys are experimenting with different solutions. It's fascinating. Quote how long does it take your laptop to generate 10000 legacy addresses? in my small test, I find that generating legacy addresses using the bit package is about twice as fast as generating bech32 ones. My tests: Code: from bit import PrivateKey Output: Code: Number of iterations: 10 |