ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
477 stars 186 forks source link

Can I use bitcoin-core in the browser? #79

Open takahser opened 5 years ago

takahser commented 5 years ago

I was wondering, if it's possible to use this library in the browser. Currently, I use bitcoinjs-lib in a VUE.js app to build transactions and I intend to use bitcoin-core for connecting to the network and broadcast the already signed transactions.

To test the integration, I'm using this simple code:

const Client = require('bitcoin-core');

const client = new Client({
  host: 'localhost',
  port: 1337,
  username: 'alice',
  password: 'foo'
});

client.getBlockchainInfo((error, help) => {
  console.log('info: ', help);
  console.log('error: ', error);
});

For testing, I ran it in 3 different apps:

TypeError: Failed to fetch
    at _bluebird.default.try (webpack-internal:///./node_modules/bitcoin-core/dist/src/index.js:168:27)
From previous event:
    at Client.command (webpack-internal:///./node_modules/bitcoin-core/dist/src/index.js:154:33)
    at apply (webpack-internal:///./node_modules/lodash/lodash.js:475:27)
    at Client.wrapper [as getBlockchainInfo] (webpack-internal:///./node_modules/lodash/lodash.js:5323:16)
    at eval (webpack-internal:///./src/services/wallet/btc-wallet.service.ts:78:8)
    at Module../src/services/wallet/btc-wallet.service.ts (http://localhost:8080/app.js:14817:1)
    at __webpack_require__ (http://localhost:8080/app.js:768:30)
    at fn (http://localhost:8080/app.js:131:20)
// etc.