ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
Bitcore是由Bitpay创建的一个模块,用于构建基于比特币和区块链的应用程序Insight也是一个使用Bitcore生成比特币浏览器的模块。本博客将指导您将Bitcore与当前运行的比特币连接起来,并使用Insight创建一个比特币浏览器。按照以下步骤在系统中实现此功能。 ## 配置 **步骤1:安装Bitcore** 运行此命令进行安装 *bitcore* ```js npm install -g bitcore ``` 如果您在执行上述命令时遇到任何权限问题(即使使用 须藤),然后按照此链接中编写的步骤解决此问题: [fixing-npm-permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions) **步骤2:安装和配置** **比特币化** 逐一运行这些命令以进行安装 *比特币* ```java sudo add-apt-repository ppa:bitcoin/bitcoin sudo apt-get update sudo apt-get install bitcoind ``` 现在配置 *比特币* 这样它可以与 *位核*。 ```java cd ~/ mkdir .bitcoin cd .bitcoin vim bitcoin.conf ``` 在此*bitcoin.conf*文件中,复制粘贴到以下行 ``` server=1 testnet=1 whitelist=127.0.0.1 txindex=1 addressindex=1 timestampindex=1 spentindex=1 zmqpubrawtx=tcp://127.0.0.1:28332 zmqpubhashblock=tcp://127.0.0.1:28332 rpcallowip=127.0.0.1 uacomment=bitcore rpcuser=bitcoin rpcpassword=local321 ``` **步骤3:配置Bitcore和** **比特币化** 现在在*.bitcoin文件夹中*创建*位核-节点。json* 文件,并在此文件中添加以下行: ```java { "network": "testnet", "port": 3001, "services": [ "bitcoind", "insight-api", "insight-ui", "web" ], "servicesConfig": { "bitcoind": { "spawn": { "datadir": "/home/ajit/.bitcoin", "exec": "bitcoind" } } } } ``` **注意**:由于我们要在*testnet*中运行*bitcoind*,*因此*我将网络作为*testnet*提供,*并且*还会根据您的系统更改*datadir*路径。 创建*包。**json** 内部文件*.bitcoin文件夹,并添加这些行: ```java { "description": "A full Bitcoin node build with Bitcore", "repository": "https://github.com/user/project", "license": "MIT", "readme": "README.md", "dependencies": { "bitcore-lib": "^v0.13.19", "bitcore-node": "^3.1.3", "insight-api": "^0.4.3", "insight-ui": "^0.4.0" } } ``` 现在,下面的命令在*.bitcoin文件夹中。* ```java npm install ``` 运行以下命令开始 *比特币* 和*洞察界面* ``` bitcored ``` 现在,在浏览器中打开 *localhost:3001 / insight /*,您将能够看到Insight UI Explorer,如下所示屏幕 射击 下面: ![流程图](http://blog.geeknr.com/index.php/archives/images/btc1.png) ## 文件 ethereum.toml **网络版本** ``` [parity] mode="active" # 这个是parity的同步模式。active表示持续同步区块;passive表示间歇性同步区块;dark表示只有在parity的rpc端口得到命令时才同步区块;last表示使用上次启动时的值 chain = "foundation" # 该参数可以让parity节点运行在不同的链上;foundation和mainnet都表示eth主网络;classic表示以太经典;ropsten等是以太坊各种开发社区搞的公有测试练,一般都有对应的水龙头网站可以获取免费的币以供测试。 base_path = "./data" # 数据存放位置,区块信息、交易信息等数据文件都会保存在指定的目录下,默认`~/.parity`中,所以为了方便管理,我们让数据生成在指定的文件夹下面 light = false # light模式只同步区块头信息,因此能快速同步到最新块,但是正常项目中都需要比较完整的区块信息,所以这里设置成false no_persistent_txqueue = true # 这个参数和交易有关。节点关闭的时候可能内存中会有部分交易没来得及发出去,如果这里设置成false,下次启动节点的时候还能继续发送这里面的交易;如果设置成true,就丢失了这些交易,需要重新发送。 [rpc] # rpc相当于http接口,可通过http请求的形式与parity交互 disable = false # 是否关闭rpc接口 port = 39842 # rpc接口的端口号 interface = "local" # rpc接口的ip,local即为localhost/127.0.0.1;也可以设置成0.0.0.0或者节点服务器所ip cors = ["*"] # 设置可访问rpc端口ip列表,设置成*即所有人都能访问 apis = ["all"] # 设置开放的api类型,api类型较多,可以以数组的形式传入多个,需要开放所有api时即设置成all hosts = ["all"] # 设置host,host其实是浏览器Host header,一般设置成all server_threads = 10 # 可同时访问的线程数量,这个设置非常有用,在geth中没有这个设置所以容易导致内存不安全 [websockets] # websockets是另一种与parity的交互形式,他能提供rpc不能提供的信息,比如能订阅新的交易并收到推送。 # 以下内容和rpc一致 disable = false port = 39843 interface = "local" origins = ["all"] # 浏览器的origin header apis = ["all"] hosts = ["all"] [ui] # parity提供一种web交互的方法,就是这个ui,生成一个网页版的交互界面 force = false disable = false port = 39844 interface = "all" path = "./data/signer" # 网页需要token来访问,这个是服务器端token的存放地址 [network] #parity与其他节点交互的网络设置,比如区块信息的同步就是靠这个网络 port = 30303 #与其他节点同步用的端口 min_peers = 10 #最少节点数量,达到这个数量的连接数以后才开始同步并认为同步的信息是正确的;同步的节点越多,就能保证信息越准确; max_peers = 100 #最大节点数量,防止连接过多节点导致消耗过多资源 ``` **使用版本** ``` [parity] mode="active" chain = "mainnet" base_path = "/data/eth_data" light = false no_persistent_txqueue = true [rpc] disable = false port = 8545 interface = "local" cors = ["*"] apis = ["all"] hosts = ["all"] server_threads = 10 [websockets] disable = false port = 8546 interface = "local" origins = ["all"] apis = ["all"] hosts = ["all"] [ui] force = false disable = false port = 8547 interface = "all" path = "/data/eth_data/signer" [network] port = 30303 min_peers = 10 max_peers = 100 ``` **原始版本** ``` [program:eth_node] command=/home/ubuntu/bin/parity --mode active --pruning fast --db-compaction ssd --cache-size 2048 --jsonrpc --jsonrpc-apis web3,eth,personal,parity,parity_accounts,traces --no-persistent-txqueue --db-path=/data/eth_data autostart=true autorestart=true startsecs=5 priority=1 stopasgroup=true killasgroup=true stderr_logfile=/data/eth_data/logs/eth_stderr.log stdout_logfile=/data/eth_data/logs/eth_stdout.log ``` **修改版本** ``` [program:eth_node] command=/home/ubuntu/bin/parity --mode active --pruning fast --db-compaction ssd --cache-size 2048 --jsonrpc --jsonrpc-apis web3,eth,personal,parity,parity_accounts,traces --ws-origins all --ws-hosts all --ws-interface all --jsonrpc-interface all --jsonrpc-cors all --no-persistent-txqueue --db-path=/data/eth_data autostart=true autorestart=true startsecs=5 priority=1 stopasgroup=true killasgroup=true stderr_logfile=/data/eth_data/logs/eth_stderr.log stdout_logfile=/data/eth_data/logs/eth_stdout.log ``` ## 附录 - [使用Bitcoind和Bitcore Insight创建Bitcoin Explorer](https://www.oodlestechnologies.com/blogs/Create-Bitcoin-Explorer-Using-Bitcoind-And-Bitcore-Insight/) ## 引言 为程序员提供优质博文、实战笔记、开发资源、学习资料内容包括:区块链、架构、Golang、Vuejs、Python、Nodejs、C/C++函数库等等。并不定期奉送各种福利。 ![我是图片](https://img.vim-cn.com/5f/63ba18d1e1e7a78c8c7f8ffc83636fd8a3798d.jpg) > 欢迎订阅:极客笔记Geeknr > > 我的名言:梦想还是要有的,万一实现了呢? > > 原文链接:http://blog.geeknr.com/index.php/archives/22/