Closed brianosaurus closed 10 years ago
Soop isn't really designed for the browser. Bitcore has its own way of compiling soop for the browser. Are you writing a project that uses both soop and bitcore? Have you compiled them both separately for the browser?
I was just going through the example on bitcore.io to listen for block, tx, and inv messages. It's the example that begins with:
var bitcore = require('bitcore');
var networks = bitcore.networks;
var Peer = bitcore.Peer;
var PeerManager = require('soop').load('bitcore/PeerManager', {
network: networks.testnet
});
You can only use PeerManager from node, not the browser.
@brianosaurus You might need to create a little node service that connects to a bitcoind instance and relays messages via websockets to the browser. Check https://github.com/bitpay/insight-api/blob/master/lib/PeerSync.js for the p2p connection to bitcoind stuff, and https://github.com/bitpay/insight-api/blob/master/app/controllers/socket.js for a simple example of using socket.io to broadcast the messages to the browser
I'll make some tests regarding using only the browser to connect to bitcoind, but I'm not sure it's possible :)
OK, I created a html example using PeerManager and couldn't make it work. It runs, but the Peer never connects. https://github.com/maraoz/bitcore/blob/sample/PeerManager-browser/examples/PeerManager.html
After digging a little, I realized it seems that browserify cannot automatically convert the 'net' module. So for now, PeerManager is not usable in the browser. The only solution I see is trying to implement the 'net' module for the browser, but I don't know if that's even possible. There's seems to be someone attempting that already, but the repo is empty: https://github.com/jryans/net-browserify
When I try to require soop in the browser (chrome) it fails (from the JS console):
require('bitcore') Object {Buffer: function, bignum: (...), base58: (...), bufferput: (...), buffertools: (...)…}
require('soop') TypeError: boolean is not a function