web3.js 报错:Uncaught TypeError: web3.sha3 is not a function
truffle(develop)> var hash = web3.sha3("Some string to be hashed");
evalmachine.<anonymous>:0
var hash = web3.sha3("Some string to be hashed");
^
Uncaught TypeError: web3.sha3 is not a function
at evalmachine.<anonymous>
at sigintHandlersWrap (node:vm:268:12)
at Script.runInContext (node:vm:137:14)
at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:364:1)
at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:379:1)
at bound (node:domain:421:15)
at REPLServer.runBound [as eval] (node:domain:432:12)
at REPLServer.onLine (node:repl:889:10)
at REPLServer.emit (node:events:394:28)
at REPLServer.emit (node:domain:475:12)
看到此错误先在控制台输入:web3.version
检查下web3.js版本
truffle(develop)> web3.version
'1.5.2'
1.5.2版本已经不再支持这种写法,换成如下写法:
var str = web3.utils.sha3("Some string to be hashed");