# Bitcoin

## **getBitcoinSignedTransaction**

The D'CENT Android SDK provides functions for signing transaction of coins.

**This function for :**&#x20;

* `.BITCOIN` - bitcoin (BTC)
* `.BITCOIN_SV` - bitcoin sv (BSV)
* `.BTC_SEGWIT` - bitcoin segwit (BTC)
* `.MONACOIN` - monacoin (MONA)
* `.LITECOIN` - litecoin (LTC)
* `.LTC_SEGWIT` - litecoin segwit (LTC)
* `.ZCASH` - zcash (ZEC)
* `.HORIZEN` - horizen (ZEN)
* `.BITCOINCASH` - bitcoin cash (BCH)
* `.DOGECOIN` - dogecoin (DOGE)
* `.BCH_ABC` - bitcoin cash abc (BCHA)
* `.ECASH` - ecash (XEC)
* `.DASH` - dash (DASH)
* `.BITCOIN_GOLD` - bitcoin gold (BTG)
* `.DIGIBYTE` - digibyte (DGB)
* `.DGB_SEGWIT` - digibyte segwit (DGB)
* `.RAVENCOIN` - ravencoin (RVN)
* `.BTC_TESTNET` - bitcoin testnet (BTCt)
* `.BTC_SEGWIT_TESTNET` - bitcoin segwit testnet (BTCt)
* `.MONA_TESTNET` - monacoin testnet (MONAt)
* `.LITE_TESTNET` - litecoin testnet (tLTC)
* `.LTC_SEGWIT_TESTNET` - litecoin segwit testnet (tLTC)
* `.ZCASH_TESTNET` - zcash testnet (TAZ)
* `.BCH_TESTNET` - bitcoin cash testnet (tBCH)
* `.DASH_TESTNET` - dash testnet (tDASH)
* `.BTG_TESTNET` - bitcoin gold testnet (tBTG)
* `.DIGIBYTE_TESTNET` - digibyte testnet (tDGB)
* `.DGB_SEGWIT_TESTNET` - digibyte segwit testnet (tDGB)
* `.RVN_TESTNET` - ravencoin testnet (tRVN)

### **Parameters**

* coinType: bitcoin networks coin type
* bitcoinTransaction: ([BitcoinTransation](#class-bitcointransaction))bitcoin transaction parameter

#### **class BitCoinTransaction**

This class to be used for bitcoin transaction.

<table><thead><tr><th width="147.33333333333331">Name</th><th width="288">Type</th><th>Description</th></tr></thead><tbody><tr><td>version</td><td><code>UInt32</code></td><td>version of bitcoin transaction. Currently 1<br>- <code>BCH</code> /<code>Dash</code>/<code>BTG</code> :  <code>2</code><br>- <code>ZCASH</code> : <code>4</code></td></tr><tr><td>input</td><td><a href="#class-unspenttransactionoutput"><code>UnspentTransactionOutput</code></a></td><td>previous transaction output information to be used</td></tr><tr><td>output</td><td><a href="#class-transactionoutput"><code>TransactionOutput</code></a></td><td>coin spending information</td></tr><tr><td>locktime</td><td><code>UInt32</code></td><td>locktime for this transaction</td></tr><tr><td>optionParam</td><td><code>String</code></td><td>(optional)option parameter for this transaction in case <code>ZCASH</code></td></tr></tbody></table>

#### **class UnspentTransactionOutput**

The class for previous transaction output information to be used for bitcoin network transaction.

<table><thead><tr><th width="115.33333333333331">Name</th><th width="145">Type</th><th>Description</th></tr></thead><tbody><tr><td>prev_tx</td><td><code>String</code></td><td>full of previous transaction data</td></tr><tr><td>utxo_idx</td><td><code>UInt32</code></td><td>index of previous transaction output to be sent</td></tr><tr><td>type</td><td><a href="#enum-btctxtype"><code>BtcTxtype</code></a></td><td>bitcoin transaction type for this UTXO</td></tr><tr><td>key</td><td><code>String</code></td><td>BIP44 key path for unlocking UTX</td></tr></tbody></table>

#### class TransactionOutput

The class for coin spending information of Bitcoin network Transaction

<table><thead><tr><th width="105.33333333333331">Name</th><th width="152">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td><code>UInt64</code></td><td>amount of coin to spend. Satoshi unit.</td></tr><tr><td>to</td><td><code>[String]</code></td><td>if <code>type</code> is <code>p2pkh</code> or <code>p2sh</code>, Base58Check encoded address of the receiver.<br>The value of the field may follow the rule of version prefix.(<code>BITCOIN_BASE58CHECK</code>)<br>if the type is <code>p2pk</code> , Base58Check encoded non-compressed public key without version prefix.<br>if the type is <code>multisig</code> , Base58Check encoded non-compressed public key (without version prefix) list.<br>if the type is <code>change</code> , BIP44 formatted PATH to get change address. In this case, the transaction type is assumed as <code>p2pkh</code></td></tr><tr><td>type</td><td><a href="#enum-btctxtype"><code>BtcTxtype</code></a></td><td>bitcoin network transaction type or this field can indicate output as a <code>change</code></td></tr></tbody></table>

#### **enum BtcTxtype**

* `p2Pkh`: pay to public key hash
* `p2Pk`: pay to public key
* `p2Sh`: pay to script hash
* `change`: indicate output as a change

### **Returns**

* result: (Bool) `true` if successful, `false` if error occurred
* txData: signed transaction

**Example**

```swift
let transactionOutput : TransactionOutput = TransactionOutput()
let unspentTransactionOutput : UnspentTransactionOutput = UnspentTransactionOutput()
var unspenttxOut : [UnspentTransactionOutput] = [UnspentTransactionOutput()]
  
unspenttxOut.append(unspentTransactionOutput)
  
let BtcTxData : BitcoinTransaction = BitcoinTransaction(version: 0, input: unspenttxOut, output: [transactionOutput], locktime: 0)
  
// test data
BtcTxData.version = 1
BtcTxData.input[1].prev_tx = "0100000001001355540aa694ddde95548de76168666f33d8fad420fab6c554180846676df1000000006a47304402205089f4b1bdb1f96786f4750af3c16a23c73b60de0fe3cfec0da906a181eea645022078047d56dded692477d35052e9179ac71f79c6ec6b5f49941056c03663255be9012103ac2a317f777d63a6bac857ba07e30920a0f2ebd3f99f15a92b8d295791a971f6ffffffff0230750000000000001976a914848d227771119767a8c08ee0b105633cbff2d6b688ac77180000000000001976a9145dadfc1f7c4548336912f23311b424310d6533c088ac00000000"
BtcTxData.input[1].type = BtcTxtype.p2Pkh
BtcTxData.input[1].utxo_idx = 1
BtcTxData.input[1].key = "m/44'/0'/0'/1/4"
BtcTxData.input[0].prev_tx = "0100000001076524b52baf87fe521e5b8a910fadd91c944f952520677def057e346a96380d000000006a473044022045a30be5dc493c36a3a55fd522b4aa2d795f49bb8b61507e1fca1c15819142c1022010846e11893840e521b277f31c1ca835d352fb582633e5ac95106d0ed52d1654012103b72bcab65c4ea43f4b700220729bdde9638c3bb70cc66b7a0de30738e8241382ffffffff0210270000000000001976a9149189ffd2039f1824de14562e592dc4bccaa57d6e88ac6a290000000000001976a9147046ed0f139552ada485f925e74f6576016fc55e88ac00000000"
BtcTxData.input[0].type = BtcTxtype.p2Pkh
BtcTxData.input[0].utxo_idx = 0
BtcTxData.input[0].key = "m/44'/0'/0'/0/2"
BtcTxData.output[0].to[0] = "1K8EfJgWR16Wo3Ejb3AtMk2mfoeAjmMtDL"
BtcTxData.output[0].type = BtcTxtype.p2Pkh
BtcTxData.output[0].value = 10000
BtcTxData.locktime = 0
  
DcentMgr.getBitcoinSignedTransaction(coinType: .BITCOIN, bitcoinTransaction: BtcTxData){ (result, txData) in
    if result == false {
        print("FAIL !!!")
    }else{
        print(txData)
    }
}
```
