Web3.js - 选项http:// localhost:8545 / net :: ERR_CONNECTION_REFUSED

时间:2017-12-25 14:56:54

标签: javascript php node.js web3js web3

我正在尝试为网站配置web3.js。我希望使用以太坊进行身份验证。

我收到以下错误:

web3-light.js:4327 OPTIONS http://localhost:8545/ net::ERR_CONNECTION_REFUSED
HttpProvider.send   @   web3-light.js:4327
RequestManager.send @   web3-light.js:6334
get @   web3-light.js:6237
watchBalance    @   test.php:17
onclick @   test.php:31 

1 个答案:

答案 0 :(得分:1)

您连接到以太坊节点的本地主机提供程序。确保使用正确的提供程序,例如infura.io

<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>

<script>
  if (typeof web3 !== 'undefined') {
    web3 = new Web3(web3.currentProvider)
  } else {
    // Set the provider you want from Web3.providers
    web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io"))
  }
</script>