How to use the bitcore-lib.Unit 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 y12studio / dltdojo / docs / api / runkit / fee.js View on Github external
// https://runkit.com/y12/58ada40ff01e960014715192
var request = require('request')
var bitcore = require("bitcore-lib")
var _ = require("lodash")
var Unit = bitcore.Unit
const coindeskapi = 'https://api.coindesk.com/v1/bpi/currentprice/TWD.json'
const feeapi = 'https://bitcoinfees.21.co/api/v1/fees/recommended'
// https://bitcoinfees.21.co/api
const avgbytes = 250

function saToBtc(satoshis) {
    return Unit.fromSatoshis(satoshis).toBTC()
}

function getTwdFee(cb) {
    request({
        url: feeapi,
        json: true
    }, (err, resp, fee) => {
        // console.log(fee)
        // { fastestFee: 160, halfHourFee: 160, hourFee: 140 }
github bitpay / bitcore-channel / regtest / index.js View on Github external
'use strict';

var _ = require('lodash');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var chai = require('chai');
var should = chai.should();
var spawn = require('child_process').spawn;
var async = require('async');
var bitcore = require('bitcore-lib');
var Unit = bitcore.Unit;
var CLTVTransaction = require('../lib/transaction/transaction');
var Transaction = bitcore.Transaction;
var PrivateKey = bitcore.PrivateKey;
var BitcoinRPC = require('bitcoind-rpc');
var Consumer = require('../lib/consumer');
var Provider = require('../lib/provider');
var Script = require('../lib/transaction/script');

var rpcConfig = {
  protocol: 'http',
  user: 'bitcoin',
  pass: 'local321',
  host: '127.0.0.1',
  port: '58332',
  rejectUnauthorized: false
};
github bitpay / bitcore-node / regtest / utils.js View on Github external
'use strict';

var bitcore = require('bitcore-lib');
var _ = require('lodash');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var fs = require('fs');
var async = require('async');
var spawn = require('child_process').spawn;
var http = require('http');
var Unit = bitcore.Unit;
var Transaction = bitcore.Transaction;
var PrivateKey = bitcore.PrivateKey;
var assert = require('assert');

var Utils = function(opts) {
  this.opts = opts;
};

Utils.prototype.writeConfigFile = function(fileStr, obj) {
  fs.writeFileSync(fileStr, JSON.stringify(obj));
};

Utils.prototype.toArgs = function(opts) {
  return Object.keys(opts).map(function(key) {
    return '-' + key + '=' + opts[key];
  });
github ninjadotorg / handshake-app / src / pages / Wallet / btc.js View on Github external
.then((fee) => {
        fee = JSON.parse(fee);
        const txFee = bitcore.Unit.fromBTC(fee[blocks]).toSatoshis();
        console.log(`data.txFee${txFee}`);
        resolve(txFee);
      })
      .catch((err) => {
github bijeebuss / icewallet / bin / src / CommandLine / IceWalletPrivate.js View on Github external
"use strict";
const fs = require('fs');
let qrcode = require('qrcode-terminal');
let unit = require('bitcore-lib').Unit;
let intl = require('intl');
const PrivateWalletService_1 = require('../Services/PrivateWalletService');
const IceWallet_1 = require('./IceWallet');
const PrivateWalletInfo_1 = require('../Models/PrivateWalletInfo');
const inquirer = require('inquirer');
class IceWalletPrivate extends IceWallet_1.default {
    loadWalletFromInfo(callback) {
        inquirer.prompt({
            name: 'password',
            type: 'password',
            message: 'enter your password to open the wallet',
        })
            .then((answers) => {
            let password = answers['password'].toString();
            console.log('loading and decrypting wallet info from' + this.pathToWalletInfo);
            console.log('this might take a minute');
github bijeebuss / icewallet / bin / src / Models / PrivateWallet.js View on Github external
PrivateWalletService.prototype.verifyTransaction = function (transaction, fee, callback) {
        console.log('Please verify this transaction');
        transaction.outputs.forEach(function (output) {
            console.log('Send: ' + bitcore.Unit.fromSatoshis(output._satoshis).toBTC());
            console.log('To:   ' + output._script.toAddress().toString());
        });
        console.log('Fee:  ' + bitcore.Unit.fromSatoshis(fee).toBTC());
        var rl = readline.createInterface({
            input: process.stdin,
            output: process.stdout
        });
        rl.question('answer y/n\n', function (answer) {
            rl.close();
            if (answer == 'y') {
                return callback(null);
            }
            else if (answer == 'n') {
                return callback('user declined transaction');
            }
            else {
                console.log('answer either "y" or "n"');
                return callback('invalid answer');
            }
github bijeebuss / icewallet / bin / src / CommandLine / IceWalletPublic.js View on Github external
"use strict";
const fs = require('fs');
let unit = require('bitcore-lib').Unit;
let intl = require('intl');
const inquirer = require('inquirer');
const PublicWalletService_1 = require('../Services/PublicWalletService');
const PublicWalletInfo_1 = require('../Models/PublicWalletInfo');
const IceWallet_1 = require('./IceWallet');
class IceWalletPublic extends IceWallet_1.default {
    createNewWallet(callback) {
        inquirer.prompt([
            {
                name: 'password1',
                type: 'password',
                message: 'create a password',
                validate: (password) => { if (!password)
                    return 'Password required';
                else
                    return true; }
github ninjadotorg / handshake-app / src / services / Wallets / Bitcoin.js View on Github external
async getFee(blocks = NB_BLOCKS, toBTC) {
    const url = `${this.network}/utils/estimatefee?nbBlocks=${blocks}`;
    const response = await axios.get(url);

    if (response.status === 200) {
      let txFee = '';
      if (toBTC) {
        txFee = bitcore.Unit.fromBTC(response.data[blocks]).toBTC();
      } else {
        txFee = bitcore.Unit.fromBTC(response.data[blocks]).toSatoshis();
      }
      return txFee;
    }
    return false;
  }
github bitpay / bitcore-node / lib / services / address / index.js View on Github external
'use strict';

var BaseService = require('../../service');
var inherits = require('util').inherits;
var async = require('async');
var index = require('../../');
var log = index.log;
var bitcore = require('bitcore-lib');
var Unit = bitcore.Unit;
var _ = bitcore.deps._;
var lodash = require('lodash');
var Encoding = require('./encoding');
var Transform = require('stream').Transform;
var assert = require('assert');
var utils = require('../../utils');

var AddressService = function(options) {

  BaseService.call(this, options);
  this._header = this.node.services.header;
  this._block = this.node.services.block;
  this._timestamp = this.node.services.timestamp;
  this._transaction = this.node.services.transaction;
  this._network = this.node.network;
  this._db = this.node.services.db;
github ninjadotorg / handshake-app / src / services / Wallets / Bitcoin.js View on Github external
async getFee(blocks = NB_BLOCKS, toBTC) {
    const url = `${this.network}/utils/estimatefee?nbBlocks=${blocks}`;
    const response = await axios.get(url);

    if (response.status === 200) {
      let txFee = '';
      if (toBTC) {
        txFee = bitcore.Unit.fromBTC(response.data[blocks]).toBTC();
      } else {
        txFee = bitcore.Unit.fromBTC(response.data[blocks]).toSatoshis();
      }
      return txFee;
    }
    return false;
  }