Bitcoin

getBitcoinSignedTransaction

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

This function for :

  • .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)bitcoin transaction parameter

class BitCoinTransaction

This class to be used for bitcoin transaction.

class UnspentTransactionOutput

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

class TransactionOutput

The class for coin spending information of Bitcoin network Transaction

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

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)
    }
}

Last updated