Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it programatically? #24

Open
hasanparasteh opened this issue Dec 25, 2022 · 2 comments
Open

How to use it programatically? #24

hasanparasteh opened this issue Dec 25, 2022 · 2 comments

Comments

@hasanparasteh
Copy link

This library print the address data very pretty but when you want to use it's API to get some information out of it and get different addresses it become really frustrating..Please review and setup some helper functions to retrieve each address accordingly

@wpolk
Copy link

wpolk commented Apr 28, 2024

Yeah I need to print 100 different keys and addresses and it only prints the same ones each time I run it. How do I get it to print different keys so I don't have to run the python file 100 different times?

@wpolk
Copy link

wpolk commented Apr 28, 2024

SOLUTION: Use wallet = Wallet() every time you need new keys. Because whenever you get a private key using a function like wallet.key.__dict__['mainnet'].__dict__['wif'] for example, it is still referencing that same wallet variable that was declared earlier.

For example, this is my script:

from bitcoinaddress import Wallet

privs = []
pubs = []
addrs = []

i = -1
for i in range(100):
    wallet = Wallet()

    privs.append(wallet.key.__dict__['mainnet'].__dict__['wif'])
    pubs.append(wallet.address.__dict__['pubkey'])
    addrs.append(wallet.address.__dict__['mainnet'].__dict__['pubaddr1'])


for i in privs:
    print(i)
print()
for i in pubs:
    print(i)
print()
for i in addrs:
    print(i)

(At first i had the wallet = Wallet() before the for loop)

@hasanparasteh You need to use the last part of the documentation: https://github.com/fortesp/bitcoinaddress?tab=readme-ov-file#example-4---check-attributes to get specific data from the wallet. You can also use for loops to get multiple addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants