bitcoinjs-lib/test/integration/advanced.js

31 lines
908 B
JavaScript
Raw Normal View History

/* global describe, it */
2015-02-23 00:36:57 +01:00
var bitcoin = require('../../')
2015-08-07 06:47:07 +02:00
var blockchain = require('./_blockchain')
2015-02-23 00:36:57 +01:00
describe('bitcoinjs-lib (advanced)', function () {
2015-09-08 08:17:34 +02:00
it('can create an OP_RETURN transaction', function (done) {
this.timeout(30000)
var network = bitcoin.networks.testnet
var keyPair = bitcoin.ECPair.makeRandom({ network: network })
var address = keyPair.getAddress()
blockchain.t.faucet(address, 2e4, function (err, unspent) {
if (err) return done(err)
var tx = new bitcoin.TransactionBuilder(network)
var data = new Buffer('bitcoinjs-lib')
var dataScript = bitcoin.script.nullDataOutput(data)
tx.addInput(unspent.txId, unspent.vout)
tx.addOutput(dataScript, 1000)
tx.addOutput(blockchain.t.RETURN, 1e4)
tx.sign(0, keyPair)
var txRaw = tx.build()
blockchain.t.transactions.propagate(txRaw.toHex(), done)
})
})
})