以太坊网络重启并开启rpc

以太坊网络重启并开启rpc,第1张

1 查找现在的进程id

ps -ef| grep geth

top | grep geth

2 重启

nohup geth --datadir '/mnt/EthereumData'  --allow-insecure-unlock >> geth.log 2>&1 &

3 安装nvm,安装node npm cnpm

nvm安装
cnpm 安装:

npm install -g cnpm -registry=https://registry.npm.taobao.org

安装web3

cnpm install web3

4启动RPC服务。远程连接服务
Geth文档

启动HTTP RPC

admin.startRPC("127.0.0.1",8546,"*","eth,net,web3,personal,admin,shh,txpool,debug,miner")

stopRPC方法用来关闭当前启动的HTTP RPC端结点。由于一个Geth节点 只能同时启动一个HTTP端结点,因此stopRPC方法不需要参数,其返回 值为一个布尔值,表示端结点是否成功关闭

admin.stopRPC()

5 测试js文件:

vim te.js

获取当前连接的节点个数

const Web3 = require("web3");
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8546"))
console.log("connected")
web3.eth.net.getPeerCount().then(function(result){
                        console.log(result)
}).catch(function(err){
                        console.log(err)
});

执行node te.js

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/740898.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存