Skip to content
View btcwhiz's full-sized avatar
🧐
Idea Launch
🧐
Idea Launch

Organizations

@EddieHubCommunity @alchemist35 @Sonice-Sonice-UK-Ltd @underworldorg @GladiatorsSolana @nutdotmarket

Block or report btcwhiz

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
btcwhiz/README.md

⛏ Wʜᴀᴛ ɪ ᴀᴍ ᴅᴏɪɴɢ:

  • ✍ Focusing on Fullstack and Web3 (Bitcoin, EVM, Solana) Developement.
  • 🌱 Built several significant projects based on Bitcoin, Solana network.
  • 💼 Now built Rune Pumpfun of Nutmarket, $DOG Marketplace of $DOG to the moon, Raffle, Multisigwallet of Covault on Bitcoin, Also working on creating an Rune Burn creation tool on Bitcoin.
  • 🔍 Researching Bitcoin Layer 1 | Lightning | Bitvm | Fractal | Defi

Here you go for my bitcoin tech

from bitcoinlib.wallets import Wallet
from bitcoinlib.transactions import Transaction, Output, Input
from bitcoinlib.encoding import address_to_scriptpubkey, decode

# Configurable parameters
WALLET_NAME = "My Wallet Name"
SENDER_ADDRESS = "sender_address_here"
RECIPIENT_ADDRESS = "recipient_address_here"
SENDER_PRIVATE_KEY = "private_key_here"  # WIF format
NETWORK = "bitcoin"  # Use "testnet" for testing
AMOUNT_TO_SEND = 0.001  # BTC
FEE = 0.0001  # BTC

# Create or load wallet
wallet = Wallet.create(WALLET_NAME, keys=SENDER_PRIVATE_KEY, network=NETWORK, witness_type='segwit')
sender_key = wallet.get_key(SENDER_ADDRESS)

# Fetch unspent transactions (UTXOs)
utxos = wallet.utxos_update()
if not utxos:
    raise ValueError("No UTXOs available for the sender address.")

# Select UTXOs to cover the transaction amount and fee
selected_utxos = []
total_input_value = 0
for utxo in utxos:
    selected_utxos.append(utxo)
    total_input_value += utxo.value
    if total_input_value >= AMOUNT_TO_SEND + FEE:
        break

if total_input_value < AMOUNT_TO_SEND + FEE:
    raise ValueError("Insufficient funds to cover the transaction amount and fee.")

# Create outputs
outputs = [
    Output(AMOUNT_TO_SEND, address_to_scriptpubkey(RECIPIENT_ADDRESS, network=NETWORK))
]

# Add change output if there's leftover input value
change = total_input_value - AMOUNT_TO_SEND - FEE
if change > 0:
    outputs.append(Output(change, address_to_scriptpubkey(SENDER_ADDRESS, network=NETWORK)))

# Create transaction
tx = Transaction(network=NETWORK)
for utxo in selected_utxos:
    tx.inputs.append(Input(utxo.txid, utxo.vout))
tx.outputs.extend(outputs)

# Sign transaction
tx.sign(sender_key.private_hex)

# Verify transaction
if not tx.verify():
    raise ValueError("Transaction verification failed.")

# Broadcast transaction
tx_hex = tx.raw_hex()
print(f"Raw Transaction Hex: {tx_hex}")
response = wallet.network().sendrawtransaction(tx_hex)
print(f"Transaction Broadcasted. TXID: {response}")

Service for Typescript Node Js

import * as bitcoin from "bitcoinjs-lib";
import { ECPair, payments } from "bitcoinjs-lib";
import axios from "axios";

export class BitcoinService {
  private network: bitcoin.Network;

  constructor(network: "mainnet" | "testnet") {
    this.network = network === "mainnet" ? bitcoin.networks.bitcoin : bitcoin.networks.testnet;
  }

  /**
   * Fetch UTXOs for a given Bitcoin address.
   * @param address Bitcoin address to fetch UTXOs for.
   * @returns Array of UTXOs.
   */
  async fetchUTXOs(address: string): Promise<any[]> {
    const apiUrl =
      this.network === bitcoin.networks.bitcoin
        ? `https://blockchain.info/unspent?active=${address}`
        : `https://blockstream.info/testnet/api/address/${address}/utxo`;

    try {
      const response = await axios.get(apiUrl);
      return response.data;
    } catch (error) {
      throw new Error("Error fetching UTXOs: " + error.message);
    }
  }

  /**
   * Create and sign a Bitcoin transaction.
   * @param senderAddress Sender's Bitcoin address.
   * @param privateKey WIF private key of the sender.
   * @param recipientAddress Recipient's Bitcoin address.
   * @param amount Amount to send in satoshis.
   * @param fee Transaction fee in satoshis.
   * @returns Signed raw transaction in hex format.
   */
  async createTransaction(
    senderAddress: string,
    privateKey: string,
    recipientAddress: string,
    amount: number,
    fee: number
  ): Promise<string> {
    const utxos = await this.fetchUTXOs(senderAddress);
    const keyPair = ECPair.fromWIF(privateKey, this.network);

    const psbt = new bitcoin.Psbt({ network: this.network });
    let inputValue = 0;

    // Add UTXOs as inputs
    utxos.forEach((utxo) => {
      if (inputValue < amount + fee) {
        inputValue += utxo.value;
        psbt.addInput({
          hash: utxo.txid,
          index: utxo.vout,
          witnessUtxo: {
            script: Buffer.from(utxo.script, "hex"),
            value: utxo.value,
          },
        });
      }
    });

    if (inputValue < amount + fee) {
      throw new Error("Insufficient funds.");
    }

    // Add output for recipient
    psbt.addOutput({
      address: recipientAddress,
      value: amount,
    });

    // Add change output if needed
    const change = inputValue - amount - fee;
    if (change > 0) {
      psbt.addOutput({
        address: senderAddress,
        value: change,
      });
    }

    // Sign inputs
    psbt.signAllInputs(keyPair);
    psbt.validateSignaturesOfAllInputs();
    psbt.finalizeAllInputs();

    return psbt.extractTransaction().toHex();
  }

  /**
   * Broadcast the signed transaction.
   * @param txHex Raw transaction hex.
   * @returns Transaction ID.
   */
  async broadcastTransaction(txHex: string): Promise<string> {
    const apiUrl =
      this.network === bitcoin.networks.bitcoin
        ? `https://blockchain.info/pushtx`
        : `https://blockstream.info/testnet/api/tx`;

    try {
      const response = await axios.post(apiUrl, txHex, {
        headers: { "Content-Type": "text/plain" },
      });
      return response.data.txid || response.data; // Blockstream API returns txid
    } catch (error) {
      throw new Error("Error broadcasting transaction: " + error.message);
    }
  }
}

Popular repositories Loading

  1. react-select-currency react-select-currency Public

    Forked from lsiden/react-select-currency

    Select a currency from a drop-down list of countries with auto-fill.

    JavaScript 3 1

  2. material-ui material-ui Public

    Forked from mui/material-ui

    Material-UI is a simple and customizable component library to build faster, beautiful, and more accessible React applications. Follow your own design system, or start with Material Design.

    JavaScript 3

  3. docs docs Public

    Forked from stellar-deprecated/docs

    DEPRECATED: Stellar documentation

    3

  4. react-timer-hook react-timer-hook Public

    Forked from amrlabib/react-timer-hook

    React timer hook

    JavaScript 3

  5. NFT-Marketplace NFT-Marketplace Public

    Forked from BravoNatalie/NFT-Marketplace

    A NFT marketplace that enables the creation, sale, and purchase of digital art as NFTs.

    JavaScript 3

  6. OnsenUI OnsenUI Public

    Forked from OnsenUI/OnsenUI

    Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, Rea…

    JavaScript 2