1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
615 stars 203 forks source link

Cant Delete Wallet #231

Closed suhin-soul closed 2 years ago

suhin-soul commented 2 years ago

As i had created the wallet named Wallet6 but the Wallet delete function is not working has AttributeError: type object 'Wallet' has no attribute 'wallet_delete_if_exists'

the code is `from bitcoinlib.wallets import Wallet,wallet_delete from bitcoinlib.mnemonic import Mnemonic

w = Wallet.create('Wallet6', witness_type='segwit')

Wallet.wallet_delete_if_exists('Wallet6')`

How to fix the issue

suhin-soul commented 2 years ago

Sorry guys Fixed by using Wallet_delete

ATButteaux commented 2 months ago

Having a heck of a time with this too. ChatGTP gave it a valiant effort, but told me to go ask an experienced human after about 30 failed iterations. Here's the code that results in "AttributeError: type object 'Wallet' has no attribute 'wallet_delete'"


from bitcoinlib.wallets import Wallet
from bitcoinlib.mnemonic import Mnemonic
from bitcoinlib.keys import HDKey

# Generate mnemonic seed phrase
mnemonic = Mnemonic()
seed_phrase = mnemonic.generate(strength=128)  # Adjust strength as needed (128, 192, 256)

print("Your BIP39 Seed Phrase (Write down and keep safe!):")
print(seed_phrase)

# Get passphrase and confirm it
while True:
    passphrase = input("Enter your desired passphrase (keep this secret): ")
    passphrase_confirm = input("Confirm your passphrase: ")

    if passphrase == passphrase_confirm:
        break
    else:
        print("Passphrases do not match. Please try again.")

# Generate seed from mnemonic and passphrase
seed = mnemonic.to_seed(seed_phrase, passphrase)

# Create HDKey from the generated seed
key = HDKey.from_seed(seed)

# Create a wallet using the generated key
wallet = Wallet.create(
    "MyWalletName",
    keys=key,
    network="bitcoin",
    witness_type='segwit'  # Optional: Specify witness type if needed
)

# Display wallet information
print("Wallet Name:", wallet.name)
print(wallet.info())

# Optionally remove the wallet after creation (use cautiously)
Wallet.wallet_delete("MyWalletName")

Also tried changing the last line to

wallet_delete_if_exists("MyWalletName", force=True)

But then I get "NameError: name 'wallet_delete_if_exists' is not defined"

ATButteaux commented 2 months ago

ChatGPT finally arrived at the correct code:

wallet_delete(wallet_name)
ATButteaux commented 2 months ago

er, also looks like I missed an import:

from bitcoinlib.wallets import Wallet, wallet_delete