Ethereum TypeError:无法读取属性';eth';未定义的

Ethereum TypeError:无法读取属性';eth';未定义的,ethereum,web3,ether,Ethereum,Web3,Ether,因此,我对这段代码有这个问题,似乎无法理解为什么在使用终端运行脚本时会出现此错误: (node:30800) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'eth' of undefined 对这一点有更好理解的人能提供帮助吗?谢谢。您在constructor中有一个拼写错误,因此此.web3…行永远不会运行。正确的一个是构造函数 在您的代码中还有另一个问题,当您使用websocket时,您不需要使用Htt

因此,我对这段代码有这个问题,似乎无法理解为什么在使用终端运行脚本时会出现此错误:

(node:30800) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'eth' of undefined

对这一点有更好理解的人能提供帮助吗?谢谢。

您在
constructor
中有一个拼写错误,因此
此.web3…
行永远不会运行。正确的一个是
构造函数

在您的代码中还有另一个问题,当您使用websocket时,您不需要使用
HttpProvider
只需将websocket url传递给web3即可:

this.web3 = new Web3('wss://mainnet.infura.io/ws/v3/' + projectId);

非常感谢你!我不认识这个,谢谢。
this.web3 = new Web3('wss://mainnet.infura.io/ws/v3/' + projectId);