https://ethereum.stackexchange.com/questions/23719/invalid-json-rpc-response-undefined-when-running-web3-eth-accounts-node

根据写好的脚本,传入参数

node mint_by_server.js https://api.avax-test.network/ext/bc/C/rpc 0x35AC2540CDfd427802e6487f6A3bFD49ec501231 abis/template_14.abi 'http://www.baidu.com'

打印出来后,会发现,最前边的都是正常的,但是最后会出现报错

使用curl https://api.avax-test.network/ext/bc/C/rpc进行测试是否可以连接到网络

curl https://api.avax-test.network/ext/bc/C/rpc:443

查看env_file

cat ~/env_file
export HTTP_PROXY="http://192.168.0.102:8080"
export HTTPS_PROXY="http://192.168.0.102:8080"
export http_proxy="http://192.168.0.102:8080"
export https_proxy="http://192.168.0.102:8080"

测试一些谷歌是否可以正常连接,

curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

curl https://api.avax-test.network/ext/bc/C/rpc:443
Not Foundlinlin@linlin-i5:/workspace/pns-airdrop-admin$

使用node进行测试:

node

Web3 = require('web3')

web3 = require('web3')

web3 = new Web3(new Web3.providers.HttpProvider("https://api.avax-test.network/ext/bc/C/rpc"));

web3.eth

以上几个命令都是正常运行的

但是web3.eth.accounts并不能得到数据

web3.eth.accounts
Uncaught Error: Invalid JSON RPC response: undefined
&nbsp;&nbsp;&nbsp; at Object.InvalidResponse (/workspace/pns-airdrop-admin/node_modules/web3/lib/web3/errors.js:38:16)
&nbsp;&nbsp;&nbsp; at HttpProvider.send (/workspace/pns-airdrop-admin/node_modules/web3/lib/web3/httpprovider.js:91:22)
&nbsp;&nbsp;&nbsp; at RequestManager.send (/workspace/pns-airdrop-admin/node_modules/web3/lib/web3/requestmanager.js:58:32)
&nbsp;&nbsp;&nbsp; at Eth.get [as accounts] (/workspace/pns-airdrop-admin/node_modules/web3/lib/web3/property.js:107:62)