我尝试了以下方法,它为我提供了正确的私钥地址,但我似乎无法导入它并从钱包中使用它。
>>> 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()
我认为这可能与 Key 对象和 HDKey 对象之间的差异有关。我需要导入一个普通的密钥。