How to use the bitcoinjs-lib.networks function in bitcoinjs-lib

To help you get started, we’ve selected a few bitcoinjs-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 quartzjer / pennybank / hb-sample.js View on Github external
var crypto = require('crypto');
var bitcoin = require("bitcoinjs-lib")
var helloblock = require('helloblock-js')({
  network: 'testnet'
})

// placeholder! this is just some op_return sample code from helloblock-js

function done(err)
{
  if(err) console.log("ERR",err);
  process.exit(0);
}

var key = bitcoin.ECKey.fromWIF("L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")
var address = key.pub.getAddress(bitcoin.networks.testnet).toString()

helloblock.faucet.withdraw(address, 2e4, function(err) {
  if (err) return done(err)

  helloblock.addresses.getUnspents(address, function(err, _, unspents) {
    if (err) return done(err)

    // filter small unspents
    unspents = unspents.filter(function(unspent) { return unspent.value > 1e4 })

    // use the oldest unspent
    var unspent = unspents.pop();
//    helloblock.transactions.get(unspent.txHash, function(err, res, transaction) {
//      if (err) return done(err)
//        console.log("unspent",unspent,transaction);
//    });
github blocktrail / blocktrail-sdk-nodejs / examples / not_so_simple_payment_api_usage.js View on Github external
/* jshint -W101 */
var blocktrail = require('../'); // require('blocktrail-sdk') when trying example from in your own project
var bitcoin = require('bitcoinjs-lib');

var client = blocktrail.BlocktrailSDK({
    apiKey : "YOUR_APIKEY_HERE",
    apiSecret : "YOUR_APISECRET_HERE",
    testnet : true
});

/*
 * this example is for when you're storing the primary private and backup public key yourself
 */
var primaryPrivateKey = bitcoin.HDNode.fromBase58("tprv8ZgxMBicQKsPdMD2AYgpezVQZNi5kxsRJDpQWc5E9mxp747KgzekJbCkvhqv6sBTDErTjkWqZdY14rLP1YL3cJawEtEp2dufHxPhr1YUoeS", bitcoin.networks.testnet);
var backupPublicKey = bitcoin.HDNode.fromBase58("tpubD6NzVbkrYhZ4Y6Ny2VF2o5wkBGuZLQAsGPn88Y4JzKZH9siB85txQyYq3sDjRBFwnE1YhdthmHWWAurJu7EetmdeJH9M5jz3Chk7Ymw2oyf", bitcoin.networks.testnet);

var sendTransaction = function(wallet) {
    wallet.getNewAddress(function(err, address, path) {
        if (err) {
            return console.log("getNewAddress ERR", err);
        }

        console.log('new address', address, path);

        var pay = {};
        pay[address] = blocktrail.toSatoshi(0.001);

        wallet.pay(pay, function(err, result) {
            if (err) {
                return console.log("pay ERR", err);
github mappum / webcoin / src / node.js View on Github external
constructor (opts = {}) {
    super()

    this.opts = opts

    let network = opts.network || 'bitcoin'

    // TODO: support regtest
    this.bitcoinJsNetwork = bitcoin.networks[network]
    this.params = params[network]
    if (!this.bitcoinJsNetwork || !this.params) {
      throw Error(`Unknown network "${network}"`)
    }

    this.error = this.error.bind(this)
    this.scan = this.handleErrors(this.scan)
    this.getUtxos = this.handleErrors(this.getUtxos)

    // TODO: chain state persistence
    this.chain = Blockchain({
      indexed: true,
      start: this.params.blockchain.checkpoints.slice(-1)[0],
      allowMinDifficultyBlocks:
        network === 'testnet' || network === 'regtest',
      ...opts.chainOpts
github fanatid / coloredcoinjs-lib / test / AddressManager.js View on Github external
var expect = require('chai').expect

var bitcoin = require('bitcoinjs-lib')
var networks = bitcoin.networks

var coloredcoinlib = require('../src/index')
var AddressManager = coloredcoinlib.AddressManager
var AddressStore = coloredcoinlib.store.AddressStore


describe('AddressManager', function() {
  var am, amStore

  var seedHex = '00000000000000000000000000000000'
  var masterKeyBase58 = 'xprv9s21ZrQH143K2JbpEjGU94NcdKSASB7LuXvJCTsxuENcGN1nVG7QjMnBZ6zZNcJaiJogsRaLaYFFjs48qt4Fg7y1GnmrchQt1zFNu6QVnta'
  var address0 = '18KMigSHDPVFzsgWe1mcaPPA5wSY3Ur5wS'

  beforeEach(function() {
    amStore = new AddressStore()
    am = new AddressManager(amStore)
github LightningPeach / peach-wallet-desktop / frontend / components / onchain / index.js View on Github external
getNetwork = () => {
        if (BITCOIN_SETTINGS.network === "testnet") {
            return bitcoin.networks.testnet;
        } else if (BITCOIN_SETTINGS.network === "simnet") {
            return SIMNET_NETWORK;
        }
        return bitcoin.networks.bitcoin;
    };
github swaponline / swap.react / shared / redux / actions / btcmultisig.js View on Github external
const signMessage = (message, encodedPrivateKey) => {
  const keyPair = bitcoin.ECPair.fromWIF(encodedPrivateKey, [bitcoin.networks.bitcoin, bitcoin.networks.testnet])
  const privateKey = keyPair.d.toBuffer(32)

  const signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)

  return signature.toString('base64')
}
github swaponline / swap.react / shared / redux / actions / ltc.js View on Github external
const signMessage = (message, encodedPrivateKey) => {
  const keyPair = bitcoin.ECPair.fromWIF(encodedPrivateKey, [bitcoin.networks.bitcoin, bitcoin.networks.testnet])
  const privateKey = keyPair.d.toBuffer(32)

  const signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)

  return signature.toString('base64')
}
github BlueWallet / BlueWallet / class / segwit-bech-wallet.js View on Github external
static scriptPubKeyToAddress(scriptPubKey) {
    const scriptPubKey2 = Buffer.from(scriptPubKey, 'hex');
    let ret;
    try {
      ret = bitcoin.payments.p2wpkh({
        output: scriptPubKey2,
        network: bitcoin.networks.bitcoin,
      }).address;
    } catch (_) {
      return false;
    }
    return ret;
  }
}
github blockchain / My-Wallet-V3 / src / helpers.js View on Github external
Helpers.fromBitcoinCash = (address) => {
  const { hash, version } = cashaddress.decode(address);
  switch (version) {
    case 'pubkeyhash':
      return Bitcoin.address.toBase58Check(hash, Bitcoin.networks.bitcoin.pubKeyHash);
    case 'scripthash':
      return Bitcoin.address.toBase58Check(hash, Bitcoin.networks.bitcoin.scriptHash);
    default:
      throw new Error('fromBitcoinCash: Address type not supported');
  }
};
github campfire-inc / OKIMOCHI / okimochi / config.js View on Github external
'use strict'
let mongoBaseUri
const BitcoindClient = require('bitcoin-core');
const network = process.env.BITCOIND_NETWORK || 'testnet';
const bitcoinjs = require('bitcoinjs-lib')
const bitcoinjsNetwork = network === 'mainnet' ? bitcoinjs.networks.mainnet : bitcoinjs.networks.testnet;

if (process.env.MONGO_PORT_27017_TCP_ADDR){
  mongoBaseUri =  `mongodb://${process.env.MONGO_PORT_27017_TCP_ADDR}:27017/`
} else if (process.env.mongo) {
  mongoBaseUri = `mongodb://${process.env.mongo}:27017/`
} else if(process.env.MONGO_URI ){
  mongoBaseUri = `mongodb://${process.env.MONGO_URI}:27017/`
} else {
  mongoBaseUri = `mongodb://localhost:27017/`
}

const mongoUri = mongoBaseUri + network

let TOKEN = "";
if (process.env.NODE_ENV === "development") {
  TOKEN = process.env.DEVELOP_TOKEN ? process.env.DEVELOP_TOKEN : process.env.TOKEN;