Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 使用web3 api检查余额时出错_Ethereum_Web3_Truffle - Fatal编程技术网

Ethereum 使用web3 api检查余额时出错

Ethereum 使用web3 api检查余额时出错,ethereum,web3,truffle,Ethereum,Web3,Truffle,我将按照此链接在mac os中设置以太坊环境。 在检查账户余额时 truffle(develop)> web3.fromWei(web3.eth.getBalance('0x0ac4d68c2c34a3f1324439bff3c119f4ef675a72'),'ether').toNumber() 我得到以下错误 Thrown: evalmachine.<anonymous>:0 web3.fromWei(web3.eth.getBalance('0x0ac4d68c2c

我将按照此链接在mac os中设置以太坊环境。 在检查账户余额时

truffle(develop)> web3.fromWei(web3.eth.getBalance('0x0ac4d68c2c34a3f1324439bff3c119f4ef675a72'),'ether').toNumber()
我得到以下错误

Thrown:
evalmachine.<anonymous>:0


web3.fromWei(web3.eth.getBalance('0x0ac4d68c2c34a3f1324439bff3c119f4ef675a72'),'ether').toNumber()
 ^



TypeError: web3.fromWei is not a function
at evalmachine.<anonymous>:0:6
at sigintHandlersWrap (vm.js:279:15)
at Script.runInContext (vm.js:134:14)
at runScript (/Users/jigmewangmo/Documents/MSIT/BlockChain/EthereumWorkspace/node_modules/truffle/build/webpack:/packages/core/lib/console.js:251:1)
at Console.interpret (/Users/jigmewangmo/Documents/MSIT/BlockChain/EthereumWorkspace/node_modules/truffle/build/webpack:/packages/core/lib/console.js:266:1)
at bound (domain.js:420:14)
at REPLServer.runBound [as eval] (domain.js:433:12)
at REPLServer.onLine (repl.js:700:10)
at REPLServer.emit (events.js:209:13)
at REPLServer.EventEmitter.emit (domain.js:476:20)
抛出:
评估机器:0
web3.fromWei(web3.eth.getBalance('0x0ac4d68c2c34a3f1324439bff3c119f4ef675a72'),'ether')。tonNumber()
^
TypeError:web3.fromWei不是函数
在评估机器上:0:6
在sigintHandlersWrap(vm.js:279:15)
在Script.runInContext(vm.js:134:14)
运行脚本时(/Users/jigmewangmo/Documents/MSIT/BlockChain/EthereumWorkspace/node_modules/truffle/build/webpack:/packages/core/lib/console.js:251:1)
在Console.explait(/Users/jigmewangmo/Documents/MSIT/BlockChain/EthereumWorkspace/node_modules/truffle/build/webpack:/packages/core/lib/Console.js:266:1)
绑定时(domain.js:420:14)
在REPLServer.runBound[as eval](domain.js:433:12)
在REPLServer.onLine上(repl.js:700:10)
在REPLServer.emit上(events.js:209:13)
在REPLServer.EventEmitter.emit上(domain.js:476:20)

知道为什么吗?我在网上查找了一些资源,但由于建议的解决方案仍然存在错误而感到困惑。提前感谢。

提供的源代码可能已过时。检查使用的
web3
版本,并从WEI中查找相应的文档

对于
web3
版本,请使用:

web3.utils.fromWei(web3.eth.getBalance('0x0ac4d68c2c34a3f1324439bff3c119f4ef675a72'),'ether').toNumber()