Tangem Wallet Pack of 2 - Secure Crypto Wallet - Trusted Cold Storage for Bitcoin, Ethereum, NFT's &

Tangem Wallet Pack of 2 - Secure Crypto Wallet - Trusted Cold Storage for Bitcoin, Ethereum, NFT's &
Key item features Ultimate Security: Generates a private key that remains on the card, safeguarding crypto and NFTs from hackers with EAL6+ certification and audited firmware. Versatile Compatibility: Manages over 13,000 tokens across 70+ blockchains, supporting DeFi, NFTs, and DeEx without wires, Bluetooth, or USB. Effortless Operation: Utilizes NFC for secure transactions via a mobile device and the Tangem app, enabling buying and selling crypto with various payment methods. Smart Backup: Features a second Tangem Wallet as a backup, eliminating the need for paper, pictures, or seed phrases for recovery. Durable Design: Boasts IP68 protection against environmental conditions, ensuring longevity and robust physical security. Comprehensive Support: Compatible with Bitcoin, Ethereum, Solana, XRP, USDT, and over 6,000 cryptocurrencies, integrating with dApps and WalletConnect.

LBANK

Creating bitcoin transactions using bitcoinlib

Just found out stack overflow had a site for bitcoin anyways... I am here today to look for an answer of a long standing question of mine, I have been trying to make a python file which uses bitcoinlib to send a transaction with 2 outputs, 1 to a selected wallet and 1 to a fee collector wallet. When I run my code it says "Error occurred: Create transaction: No unspent transaction outputs found or no key available for UTXO's".

I have tried looking around for help, asked AI, sent funds to all accolated address of the private key (legacy, segwit, ect) to ensure it had funds and still says the same.

This is the function im using :

import random
import string
from bitcoinlib.wallets import Wallet, wallet_delete
from bitcoinlib.transactions import Output
from bitcoinlib.keys import Key

def send_with_fee(wif_key, recipient_address, amount_btc):
    """
    Send BTC to a user-specified address and include a small service fee in a batch transaction.

    :param wif_key: WIF private key (Testnet)
    :param recipient_address: Destination address from the user
    :param amount_btc: BTC to send to the recipient (not including fee)
    """
    fee_address = "tb1pts2mvh4yhvj0ajr8qpqtkr2xqd9v9rupaa42acfqzjqstyfcx09qcrvepf"
    fee_percent = 0.001
    fee_amount_btc = max(0.0001, round(float(amount_btc) * fee_percent, 8))

    # Convert BTC to satoshis
    amount_btc_satoshis = int(float(amount_btc) * 1e8)
    fee_amount_btc_satoshis = int(fee_amount_btc * 1e8)

    wallet_name = "wallet_" + ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))

    # Clean up any existing wallet with same name
    try:
        wallet_delete(wallet_name)
    except Exception as e:
        print(f"WWarning: {e}")

    try:
        key = Key(import_key=wif_key, network='testnet')
        w = Wallet.create(wallet_name, keys=key, network='testnet')

        outputs = [
            (recipient_address, amount_btc_satoshis),  # Use the integer value for amount
            (fee_address, fee_amount_btc_satoshis)      # Use the integer value for fee
        ]

        tx = w.transaction_create(outputs, fee=None, replace_by_fee=True)

        print(f"💌 Sent {amount_btc} BTC to {recipient_address}")
        print(f"💎 Service Fee: {fee_amount_btc} BTC to {fee_address}")
        print(f"🎉 TXID: {tx.txid}")

        return tx
    except Exception as e:
        print(f"Error occurred: {e}")


from Recent Questions - Bitcoin Stack Exchange https://ift.tt/9xE2toy
via IFTTT

Popular posts from this blog

Crypto Exec Warns Tokenization Is Moving Faster Than Expected

Bitcoin Mining Could Be Strengthening The Ruble, Russian Central Bank Says

Nigerian SEC Partners With Police To Tackle Crypto Ponzi Schemes – Details