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

To help you get started, we’ve selected a few bitcore-lib 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 fanatid / coloredcoinjs-lib / test / integration / balance.js View on Github external
it('EPOBC', async () => {
    let txId = '694dffbf830e50139c34b80abd20c95f37b1a7e6401be5ef579d6f1f973c6c4c'
    let tx = new bitcore.Transaction(fixtures[txId])
    let outIndex = 0

    let data = await cdata.getOutColorValues(
      tx, [outIndex], EPOBC, helpers.getTxFn)
    expect(data).to.be.instanceof(Map).and.to.have.property('size', 1)
    let cvs = Array.from(data.values())
    expect(cvs[0]).to.have.length(2)
    expect(cvs[0][0]).to.be.instanceof(cclib.ColorValue)
    expect(cvs[0][0].getColorDefinition()._genesis.txId).to.equal('b8a402f28f247946df2b765f7e52cfcaf8c0714f71b13ae4f151a973647c5170')
    expect(cvs[0][0].getValue()).to.equal(100000)
    expect(cvs[0][0].getColorId()).to.equal(Array.from(data.keys())[0])
  })
})
github bitpay / bitcore-node / test / services / bitcoind.unit.js View on Github external
describe('#sendTransaction', function(done) {
    var tx = bitcore.Transaction(txhex);
    it('will give rpc error', function() {
      var bitcoind = new BitcoinService(baseConfig);
      var sendRawTransaction = sinon.stub().callsArgWith(2, {message: 'error', code: -1});
      bitcoind.nodes.push({
        client: {
          sendRawTransaction: sendRawTransaction
        }
      });
      bitcoind.sendTransaction(txhex, function(err) {
        should.exist(err);
        err.should.be.an.instanceof(errors.RPCError);
      });
    });
    it('will send to client and get hash', function() {
      var bitcoind = new BitcoinService(baseConfig);
      var sendRawTransaction = sinon.stub().callsArgWith(2, null, {
github bitpay / bitcore-node / test / services / bitcoind.unit.js View on Github external
it('will handle non-standard script types', function() {
      var bitcoind = new BitcoinService(baseConfig);
      var tx = bitcore.Transaction();
      tx.addInput(bitcore.Transaction.Input({
        prevTxId: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
        script: bitcore.Script('OP_TRUE'),
        outputIndex: 1,
        output: {
          script: bitcore.Script('OP_TRUE'),
          satoshis: 5000000000
        }
      }));
      tx.addOutput(bitcore.Transaction.Output({
        script: bitcore.Script('OP_TRUE'),
        satoshis: 5000000000
      }));
      var addresses = bitcoind._getAddressesFromTransaction(tx);
      addresses.length.should.equal(0);
    });
github bitpay / bitcore-node / regtest / bitcoind.js View on Github external
it('for tx ' + i, function(done) {
        var txhex = transactionData[i];
        var tx = new bitcore.Transaction();
        tx.fromString(txhex);
        bitcoind.getTransaction(tx.hash, function(err, response) {
          if (err) {
            throw err;
          }
          assert(response.toString('hex') === txhex, 'incorrect tx data result');
          done();
        });
      });
    });
github mappum / webcoin / test / transactionStore.js View on Github external
function createTransaction () {
  var tx = new Transaction()
  tx.addData(crypto.pseudoRandomBytes(16))
  return tx
}
github fanatid / coloredcoinjs-lib / test / definitions / epobc.js View on Github external
beforeEach(() => {
    tx1 = new bitcore.Transaction()
    tx2 = new bitcore.Transaction()
    epobc = new EPOBC(1, genesis)
  })
github bitpay / bwdb / regtest / index.js View on Github external
function(next) {
          tx = bitcore.Transaction();
          var utxo = middle.utxos[0];
          tx.from({
            address: utxo.address,
            satoshis: utxo.satoshis,
            txid: utxo.txid,
            outputIndex: utxo.index,
            script: bitcore.Script.fromAddress(utxo.address)
          });
          tx.enableRBF();
          tx.to(test4Address, 5 * 1e8);
          tx.change(test4Address);
          tx.sign(testKey);
          broadcastAndGenerate(tx, function(err, data) {
            if (err) {
              return next(err);
            }
github citrusbyte / universal-wallet / packages / webapp / src / utils / btc.js View on Github external
const generateTx = ({ utxos, fromAddress, toAddress, privateKey, amount }) => {
  const tx = Transaction();
  tx.from(utxos);
  tx.to(toAddress, toSatoshi(amount));
  tx.change(fromAddress);
  try {
    tx.sign(privateKey);
    tx.serialize();
  } catch (err) {
    throw new Error(`Could not sign & serialize transaction: ${err}`);
  }
  return tx;
};
github poetapp / poet-js / src / serialization / ClaimBuilder.ts View on Github external
export function createTransaction(blockId: string, utxos: any, changeAddress: any, privateKey: any) {
    const data = Buffer.concat([
      POET,
      VERSION,
      new Buffer(blockId, 'hex')
    ])
    return new bitcore.Transaction()
      .from(utxos)
      .change(changeAddress)
      .addData(data)
      .sign(privateKey)
  }