How to use the bitcore-lib-cash.Transaction function in bitcore-lib-cash

To help you get started, we’ve selected a few bitcore-lib-cash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simpleledger / slpjs / lib / transactionhelpers.ts View on Github external
get_transaction_sig_p2sh(txHex: string, wif: string, input_index: number, input_satoshis: number, redeemScript: Buffer, sigHashType=0x41): InputSigData {
        
        // deserialize the unsigned transaction

        let txn = new Bitcore.Transaction(txHex);

        // we need to get the key pair from wif
        // this will be used by bitcore-lib input sig generation
        // NOTE: Only works for compressed-WIF format

        let ecpair = this.slp.BITBOX.ECPair.fromWIF(wif);

        // we set the previous output for the input
        // again, this is for bitcore-lib input sig generation

        txn.inputs[input_index].output = new Bitcore.Transaction.Output({
            satoshis: input_satoshis, 
            script: redeemScript
        });

        // produce a signature that is specific to this input
github simpleledger / slpjs / lib / transactionhelpers.ts View on Github external
get_transaction_sig_p2pkh(txHex: string, wif: string, input_index: number, input_satoshis: number, sigHashType=0x41): InputSigData {
        
        // deserialize the unsigned transaction

        let txn = new Bitcore.Transaction(txHex);

        // we need to get the key pair from wif
        // this will be used by bitcore-lib input sig generation
        // NOTE: Only works for compressed-WIF format

        let ecpair = this.slp.BITBOX.ECPair.fromWIF(wif);

        // we set the previous output for the input
        // again, this is for bitcore-lib input sig generation

        txn.inputs[input_index].output = new Bitcore.Transaction.Output({
            satoshis: input_satoshis, 
            script: Bitcore.Script.fromAddress(Utils.toCashAddress(ecpair.getAddress())) 
        });

        // Update input to be non-abstract type so we can get the p2pkh sign method
github simpleledger / slpjs / lib / transactionhelpers.ts View on Github external
addScriptSigs(unsignedTxnHex: string, scriptSigs: (ScriptSigP2PKH|ScriptSigP2SH|ScriptSigP2PK)[]): string {

        // deserialize unsigned transaction so we can add sigs to it

        let txn = new Bitcore.Transaction(unsignedTxnHex);
        let bip62Encoded: Buffer;
        scriptSigs.forEach(s => {

            // for p2pkh encode scriptSig

            if((s as ScriptSigP2PKH).pubKeyBuf) {  
                let sigBuf = (s as ScriptSigP2PKH).signatureBuf;
                let pubKeyBuf = (s as ScriptSigP2PKH).pubKeyBuf;
                bip62Encoded = this.slp.BITBOX.Script.encode([ sigBuf, pubKeyBuf ]);
            }

            // for p2sh encode scriptSig 

            else if((s as ScriptSigP2SH).lockingScriptBuf) {
                let unlockingBufArray = (s as ScriptSigP2SH).unlockingScriptBufArray;
                let lockingBuf = (s as ScriptSigP2SH).lockingScriptBuf;
github blockparty-sh / craft.cash / src / main.js View on Github external
app.send = (address, satoshis, callback) => {
    app.call_before('send', [address, satoshis]);

    if (! app.is_logged_in()) {
        throw new Error('blockparty: sending without being logged in');
    }

    if (! bch.Address.isValid(address)) {
        throw new Error('blockparty: invalid address');
    }

    let tx = new bch.Transaction();
    tx.from(app.get_utxos());
    tx.to(address, satoshis);
    tx.feePerKb(app.fee_per_kb);
    tx.change(app.get_address());

    tx = app.clean_tx_dust(tx);
    tx.sign(app.get_private_key());

    app.broadcast_tx(tx, (tx) => {
        if (callback) {
            callback(tx);
        }
    });

    app.call_after('send', [address, satoshis, tx]);
};
github ninjadotorg / handshake-app / src / services / Wallets / BitcoinCash.js View on Github external
amountToSend = amountBig.times(satoShiRate).toString();

      const data = {};
      if(!fee){
        fee = await this.getFee(blocks);
      }

      if (fee) {
        data.fee = fee;
        const utxos = await this.utxosForAmount(Number(amountToSend) + Number(fee));

        if (utxos != false) {
          data.utxos = utxos;
          const fromAddress = this.address;
          const privateKey = this.privateKey;
          const transaction = new bitcore.Transaction()
            .from(data.utxos)
            .change(fromAddress)
            .fee(data.fee)
            .to(toAddress, Number(amountToSend))
            .sign(privateKey);

          const rawTx = transaction.serialize();
          const txHash = await this.sendRawTx(rawTx);

          return { status: 1, message: 'messages.bitcoin.success.transaction', data: { hash: txHash.txid } };
        }

        return { status: 0, message: 'messages.bitcoin.error.insufficient' };
      }
    } catch (error) {
      return { status: 0, message: 'messages.bitcoin.error.insufficient' };
github monicanagent / cypherpoker.js / src / server / libs / adapters / BitcoinCashNative.js View on Github external
async buildRawTransaction(UTXOList, fromAddress, toAddress, signingKey, network, amountSat, feeSat) {
      var tx = new bitcoreCash.Transaction().from(UTXOList).to(toAddress, parseInt(amountSat)).change(fromAddress).fee(parseInt(feeSat)).sign(signingKey).serialize();
      return (tx);
   }
github simpleledger / slpjs / lib / bitboxnetwork.js View on Github external
return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 2, , 3]);
                        return [4 /*yield*/, this.BITBOX.RawTransactions.getRawTransaction([txid])];
                    case 1:
                        res = (_a.sent());
                        return [3 /*break*/, 3];
                    case 2:
                        e_1 = _a.sent();
                        throw Error(e_1.error);
                    case 3:
                        if (!Array.isArray(res) || res.length !== 1)
                            throw Error("BITBOX response error for 'RawTransactions.getRawTransaction'");
                        txhex = res[0];
                        txn = new Bitcore.Transaction(txhex);
                        slpMsg = this.slp.parseSlpOutputScript(txn.outputs[0]._scriptBuffer);
                        if (slpMsg.transactionType === index_1.SlpTransactionType.GENESIS) {
                            slpMsg.tokenIdHex = txid;
                            if (decimalConversion)
                                slpMsg.genesisOrMintQuantity = slpMsg.genesisOrMintQuantity.dividedBy(Math.pow(10, slpMsg.decimals));
                        }
                        else {
                            if (decimalConversion)
                                slpMsg.sendOutputs.map(function (o) { return o.dividedBy(Math.pow(10, slpMsg.decimals)); });
                        }
                        return [2 /*return*/, slpMsg];
                }
            });
        });
github BCNetio / BlockStackWallet / app / Providers / Wallets.js View on Github external
export const bchTransaction = (pKey, utxo, listOfReceivers) => {
  const pk = new bch.PrivateKey(pKey);
  const tx = bch
    .Transaction()
    .from(utxo.map(_ => ({ ..._, address: pk.toAddress().toString() })));
  listOfReceivers.forEach(receiver =>
    tx.to(receiver.key, toSatoshi(receiver.amount))
  );
  tx.sign(pk);
  return tx.toString();
};
github simpleledger / slpjs / lib / trademanager.ts View on Github external
async parseTokenOfferFromDummy(dummyHex: string): Promise {
        let txn = new Bitcore.Transaction(dummyHex);
        let slp = new Slp(this.BITBOX);
        let slpMsg: SlpTransactionDetails;
        try {
            slpMsg = slp.parseSlpOutputScript(txn.outputs[0]._scriptBuffer);
        } catch(_) {
            throw Error("Not a valid SLP transaction.");
        }
        
        let txid = txn.inputs[2].prevTxId.toString('hex');
        let vout = txn.inputs[2].outputIndex;

        let txo: TxOut|null = await this.BITBOX.Blockchain.getTxOut(txid, vout, true);

        let offer: SlpTokenOffer;

        if(txo)