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, 2022 in Blockchain by Rahul
• 9,680 points
1,380 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, 2022 by Soham
• 9,710 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,220 points
3,643 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
1,164 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
905 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,434 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
1,927 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,455 views
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, 2022 in Blockchain by Soham
• 9,710 points
988 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, 2022 in Blockchain by Soham
• 9,710 points
715 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP