最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

bitcoin - Why 'send-crypto' returns different address btc account? - Stack Overflow

programmeradmin1浏览0评论

I am trying to send btc transaction using send-crypto.
This reference blog is really helpful for me (How to send bitcoin BTC using send-crypto using WIF key in node,js)

I created btc account like this way.

  import * as bip39 from "bip39"
  import { BIP32Factory } from "bip32"
  import * as ecc from "tiny-secp256k1"
  import * as bitcoin from "bitcoinjs-lib"

    const bip32 = BIP32Factory(ecc)

    const seed = await bip39.mnemonicToSeed(mnemonic);

    // Define Bitcoin network
    const network = networkType === "mainnet" ? bitcoinworks.bitcoin : bitcoinworks.testnet;

    // Derive HD wallet root key
    const root = bip32.fromSeed(Uint8Array.from(seed), network);

    // BIP44 derivation path for Bitcoin (m/44'/0'/0'/0/index)
    const path = `m/84'/0'/0'/0/${index}`;
    const keyPair = root.derivePath(path);

    // Convert public key to Buffer
    const publicKeyBuffer = Buffer.from(keyPair.publicKey);

    // Generate SegWit Bitcoin address (Bech32)
    const { address } = bitcoin.payments.p2wpkh({
      pubkey: publicKeyBuffer,
      network,
    });

    // Private key (WIF format)
    const privateKey = keyPair.toWIF();
    const publicKey = publicKeyBuffer.toString("hex")

It returns address and privkey like this format bc1q7c8lkm...., L1seBxjV72D...

But when I use send-crypto to broadcast btc transaction, I saw different address format even though I used same privKey there.

const CryptoAccount = require("send-crypto")
const privateKeyWIF = 'L1seBxjV72D....'
const network = bitcoinworks.bitcoin
const keyPair = ECPair.fromWIF(privateKeyWIF, network)
const privateKey = keyPair.privateKey;
const account = new CryptoAccount(privateKey);

console.log(await account.address("BTC"))

`1ByBiyTeksaBtd....`

As far as I understood, those addresses(bc1q7c8lkm...., 1ByBiyTeksaBtd...) are different because first one is using P2WPKH, and second is using P2PKH.

I am wondering if I can use P2WPKH in send-crypto library.

发布评论

评论列表(0)

  1. 暂无评论