How can I import a Bitcoin paper wallet key into a bitcoinlib wallet

0 votes

I tried the following, which gives me the correct address for the private key, but I can't seem to import this and use it from a wallet.

>>> from bitcoinlib.wallets import HDWallet >>> from bitcoinlib.keys import Key >>> k = Key(import_key=pkstring, is_private=True) >>> print(k.address()) 1BZAHUFU5vgmtiwPnD1HLPiWNoD9tejndt >>> w = HDWallet.create('Wallet') >>> w.import_key(k) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.7/site-packages/bitcoinlib/wallets.py", line 1381, in import_key network = check_network_and_key(key, default_network=self.network.name) File "/usr/local/lib/python3.7/site-packages/bitcoinlib/keys.py", line 89, in check_network_and_key kf = get_key_format(key) File "/usr/local/lib/python3.7/site-packages/bitcoinlib/keys.py", line 148, in get_key_format elif len(key) == 130 and key[:2] == '04' and not isprivate: TypeError: object of type 'Key' has no len()


I think it may have something to do with the difference between a Key object and an HDKey object. I need to import an ordinary key.

Apr 6 in Blockchain by Rahul
• 8,980 points
24 views

1 answer to this question.

0 votes

Your code should work in the latest version of bitcoinlib.

You could also import the key directly into the wallet without creating a Key object first:

w = HDWallet.create('Wallet') w.import_key(pkstring)

Or just create a wallet with a single key from your key string:

w = HDWallet.create('Wallet2', keys=pkstring, scheme='single')

answered Apr 12 by Soham
• 8,730 points

Related Questions In Blockchain

0 votes
1 answer

How can i import the csv/excel files into my contract and record the transaction ?

You can not directly import an excel/csv ...READ MORE

answered Apr 16, 2019 in Blockchain by Omkar
• 69,190 points
1,666 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 18, 2018 in Blockchain by sapan
495 views
+1 vote
1 answer

How can I initiate a transaction on ethereum private network using mobile device?

There is no android wallet to connect ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,400 points
384 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
609 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
926 views
0 votes
1 answer
0 votes
1 answer

How can merkle trees help validate the content of a block in a blockchain

As long as they are centralized entities ...READ MORE

answered Feb 28 in Blockchain by Soham
• 8,730 points
71 views
0 votes
1 answer

Bitcoin - BitGO - Save all wallet objects into Array of Objects

 After noticing your following code: docs.forEach(function(address) { console.log(address); var ...READ MORE

answered Apr 12 in Blockchain by Soham
• 8,730 points
29 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP