1

Error: Web3ProviderEngine does not support synchronous requests.

That's what I get when I use the following command from Truffle Console:

truffle(ropsten)> web3.eth.getBlock('latest').then(console.log)

Any ideas why this is happening?

The full error is as follows:

truffle(ropsten)> web3.eth.getBlock('latest').then(console.log)
Error: Web3ProviderEngine does not support synchronous requests.
    at ProviderError.ExtendableError (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-error/index.js:10:1)
    at new ProviderError (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/error.js:17:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:71:1
    at HDWalletProvider.send (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:109:1)
    at RequestManager.send (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:58:1)
    at Eth.send [as getBlock] (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/method.js:145:1)
    at evalmachine.<anonymous>:1:10
    at ContextifyScript.Script.runInContext (vm.js:59:29)
    at Object.runInContext (vm.js:120:6)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/console.js:164:1)
    at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/repl.js:119:1)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:468:10)
    at emitOne (events.js:116:13)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.Interface._line (readline.js:631:8)
    at REPLServer.Interface._ttyWrite (readline.js:911:14)
    at REPLServer.self._ttyWrite (repl.js:537:7)
    at ReadStream.onkeypress (readline.js:160:10)
    at emitTwo (events.js:126:13)
    at ReadStream.emit (events.js:214:7)
    at emitKeys (internal/readline.js:420:14)
    at emitKeys.next (<anonymous>)
    at ReadStream.onData (readline.js:1011:36)
    at emitOne (events.js:116:13)
    at ReadStream.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at ReadStream.Readable.push (_stream_readable.js:208:10)
    at TTY.onread (net.js:594:20)
truffle(ropsten)> 
1
  • Which version of truffle do you use? Commented Dec 17, 2018 at 17:13

1 Answer 1

0

As far as I can read it from your Stacktrace, you're using HDWalletProvider.

It seems like it doesn't support synchronous requests, so you'll have to pass a callback

web3.eth.getBlock('latest', function(err, res) {console.log(res)})

Moreover, web3.eth.getBlock('latest').then(console.log) will not work, since it's not a promise. If your provider would support synchronous calls, you would only have to call console.log(web3.eth.getBlock('latest'))

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.