bitcoinjs-lib/test/integration/advanced.js
2016-10-13 18:05:02 +11:00

30 lines
908 B
JavaScript

/* global describe, it */
var bitcoin = require('../../')
var blockchain = require('./_blockchain')
describe('bitcoinjs-lib (advanced)', function () {
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, 5e4, 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, 4e4)
tx.sign(0, keyPair)
var txRaw = tx.build()
blockchain.t.transactions.propagate(txRaw.toHex(), done)
})
})
})