<p>I'm trying to build a nodejs command with commander, bitcoinjs-lib, bitcoincashjs, blocktrail-sdk. Currently I got the problem when trying to spend the Bitcoin Cash of segwit address.</p>

<p>Example:</p>

<ul>
<li>A is BTC segwit address</li>
<li>B, C is Bitcoin Cash address</li>
<li>B send Bitcoin Cash to A</li>
</ul>

<p>=> How to send Bitcoin Cash of A to C?</p>

<p>I've tried with this code but failed.</p>

<pre><code>bch.Networks.defaultNetwork = bch.Networks.testnet;

var toAddress = "xxxx";

var blocktrail_client = blocktrail.BlocktrailSDK({
    apiKey: "xxxx",
    apiSecret: "xxxx",
    network: "BCC",
    testnet: true
});

var privKey = "xxxx";
var privateKey = new bch.PrivateKey(privKey);
var address = privateKey.toAddress().toString();

blocktrail_client
    .addressUnspentOutputs(address)
    .then(async (res, error) =&gt; {
        if (error) {
            return console.log(error);
        }
        if (res.data.length == 0) {
            return console.log("Error. Nothing to send.")
        }

    var tx = res.data[0];

    utxo = {
        txId: tx.hash,
        outputIndex: 0,
        address,
        script: tx.script_hex,
        satoshis: tx.value
    };

    const transaction = new bch.Transaction()
        .from(utxo)
        .to(toAddress, tx.value - 1000)
        .fee(1000)
        .sign(privateKey);

    blocktrail_client.sendRawTransaction(
        transaction.toString(),
        (error, hash) =&gt; {
            if (error) {
                return console.log(error);
            }
            return console.log(hash);
        }
    );
})
.catch(error =&gt; console.log(error));
</code></pre>

CC BY-SA 3.0
2018-03-30T09:48:10.857Z
you do not need to sign this transaction
amaclin
CC BY-SA 3.0
2018-03-30T10:06:45.127Z
@amaclin thank you for your comment, would you please help me explain more details?
Tho Nguyen
CC BY-SA 3.0
2018-03-31T18:09:53.500Z
This makes no sense. You can't send BCH to a BTC address; it's a different network, different blockchain, and different currency. You can't send USD to a BTC address either. You'll need to find an exchange or someone willing to trade. Also, segwit does not exist on the BCH chain.
Pieter Wuille
CC BY-SA 4.0
2018-11-27T17:19:59.187Z
@PieterWuille: Actually, Bitcoin addresses are valid on the Bitcoin Cash network, so you can send BCH to an address that is part of a Bitcoin wallet. This has been a major headache to wallet provider services. Most cases are fairly easy to fix, but recovering funds sent to a segwit address is more complicated.
Murch
<bitcoin-cash><segregated-witness><cross-chain-recovery>
How to send Bitcoin Cash from BTC segwit address?
Tho Nguyen
# How to send Bitcoin Cash from BTC segwit address?

(Asked by: username_0 on 2018-03-30)

I'm trying to build a nodejs command with commander, bitcoinjs-lib, bitcoincashjs, blocktrail-sdk. Currently I got the problem when trying to spend the Bitcoin Cash of segwit address.
Example:

A is BTC segwit address
B, C is Bitcoin Cash address
B send Bitcoin Cash to A

=> How to send Bitcoin Cash of A to C?
I've tried with this code but failed.
bch.Networks.defaultNetwork = bch.Networks.testnet;

var toAddress = "xxxx";

var blocktrail_client = blocktrail.BlocktrailSDK({
    apiKey: "xxxx",
    apiSecret: "xxxx",
    network: "BCC",
    testnet: true
});

var privKey = "xxxx";
var privateKey = new bch.PrivateKey(privKey);
var address = privateKey.toAddress().toString();

blocktrail_client
    .addressUnspentOutputs(address)
    .then(async (res, error) => {
        if (error) {
            return console.log(error);
        }
        if (res.data.length == 0) {
            return console.log("Error. Nothing to send.")
        }

    var tx = res.data[0];

    utxo = {
        txId: tx.hash,
        outputIndex: 0,
        address,
        script: tx.script_hex,
        satoshis: tx.value
    };

    const transaction = new bch.Transaction()
        .from(utxo)
        .to(toAddress, tx.value - 1000)
        .fee(1000)
        .sign(privateKey);

    blocktrail_client.sendRawTransaction(
        transaction.toString(),
        (error, hash) => {
            if (error) {
                return console.log(error);
            }
            return console.log(hash);
        }
    );
})
.catch(error => console.log(error));

**Tags:** bitcoin-cash, segregated-witness, cross-chain-recovery

> **Comments:**
> **username_1**: you do not need to sign this transaction  
> **username_0**: @username_1 thank you for your comment, would you please help me explain more details?  
> **username_2**: This makes no sense. You can't send BCH to a BTC address; it's a different network, different blockchain, and different currency. You can't send USD to a BTC address either. You'll need to find an exchange or someone willing to trade. Also, segwit does not exist on the BCH chain.  
> **username_3**: @PieterWuille: Actually, Bitcoin addresses are valid on the Bitcoin Cash network, so you can send BCH to an address that is part of a Bitcoin wallet. This has been a major headache to wallet provider services. Most cases are fairly easy to fix, but recovering funds sent to a segwit address is more complicated.  

---

## 0 answers

