我跑:
geth --rinkeby --rpc --rpcport=8545 --rpcaddr=192.168.1.37 它在控制台中工作:
geth attach http://192.168.1.37:8545
> eth.syncing
false
> eth.accounts
["0xb4e4634e9eebb5a741b6c6beb7afb7746c09cbfc"]松露迁移也适用于
module.exports = {
networks: {
"geth": {
network_id: "*",
host: "192.168.1.37",
port: 8545
},
}
};但当我跑的时候
Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.1.37:8545"));
console.log(web3.currentProvider);
web3.eth.getAccounts().then(e => console.log(e));我花了几分钟就得到:
当我使用-rpcaddress= localhost时,它可以工作,但当然只能从localhost使用。
我不管我用的是什么版本。目前使用:
geth: 1.9.6-稳定
web3: 1.2.1
松露v5.0.38
有什么想法吗?请!
发布于 2019-10-16 18:53:46
我不知道你当前项目的基础设施。
然而,值得尝试改变:
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));至:
web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.1.37:8545"));您也在此IP中使用geth attach,因此它可能解决您的问题。
编辑1:由于这似乎是网络的一个问题,这里是您需要做的:
您的rpcaddr很可能是127.0.0.1。这意味着只有服务器/本地机器才能访问此节点/块链。
因此,您需要进行更改,以便允许外部连接。
这样做的简单方法是使用rpcaddr 0.0.0.0。但这很不安全。现在每个人都可以访问您的节点。因此,您应该指定哪个IP可以访问您的节点。
或者手动输入您的设备IP (希望访问),或者在它周围构建一个API,为您处理这些内容。
以下是允许从所有设备连接的简单方法:
使用指定的以下两个属性启动geth:
--rpcaddr 0.0.0.0和--rpccorsdomain "*"
。
编辑2:现在您的命令应该如下所示:
geth --rinkeby --rpc --rpcport=8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*"
发布于 2019-10-17 21:13:19
通过不安全的http连接调用web3似乎是个问题,尽管我不知道为什么。我就是为了让它发挥作用而做的:
建立一个ngrok安全隧道
按以下方式运行:
geth --rinkeby --rpc --rpcport=8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*"使用以下URL从任何地方连接。它适用于松露、geth控制台和web3js。
https://<myid>.ngrok.io无论如何,这可能是一个安全的解决方案,但是如果没有它就能开发,那就太好了。
发布于 2020-03-31 15:25:12
如果您像我一样,并且是docker或docker-compose中的菜鸟,不要使用localhost引用其他容器。改为使用容器名称。因此,如果您的停靠者编写的文件是:
version: '3'
services:
ganache:
image: trufflesuite/ganache-cli
container_name: ganache-dev
volumes:
- ./ganache:/home/ganache
expose:
- "8545"
env_file:
- .env
ports:
- "8545:8545"连接到http://ganache:8545。希望这能帮上忙。
https://ethereum.stackexchange.com/questions/76767
复制相似问题