本人使用ip+端口的方式连接本地geth有异常
换个思路,可以使用ipc的方式
- 连接方式
const net = require("net");
const Web3 = require("web3");
const ipcPath = "/Users/xxxxx/geth.ipc";
const web3 = new Web3(ipcPath, net);
web3.eth.getAccounts(console.log);
- 如何获取ipcPath呢
在geth启动的时候
geth --datadir . --networkid 666 console
控制台会有输出
先临时解决了
最终解决了
启动的时候加参数 --http
完整启动命令 geth --datadir . --networkid 666 console --http
参考文档:https://geth.ethereum.org/docs/rpc/server