Truffle – How to Fix ‘Cannot Find Module truffle-hdwallet-provider’ Error

hardware-walletsnodejstruffle

I got the following errors while trying to deploy my smart contract:

sers-Air:lottery user$ node deploy.js

internal/modules/cjs/loader.js:582

    throw err;

    ^



Error: Cannot find module 'truffle-hdwallet-provider'

    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)

    at Function.Module._load (internal/modules/cjs/loader.js:506:25)

    at Module.require (internal/modules/cjs/loader.js:636:17)

    at require (internal/modules/cjs/helpers.js:20:18)

    at Object.<anonymous> (/Users/user/Documents/prod/EthereumCasts/lottery/deploy.js:1:88)

    at Module._compile (internal/modules/cjs/loader.js:688:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)

    at Module.load (internal/modules/cjs/loader.js:598:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

users-Air:lottery user$



I also tried to change it to const result = await new web3.eth.Contract(JSON.parse(interface))

.deploy({ data: '0x' + bytecode })

.send({ from: accounts[0] });

as suggested in the other thread but it didn't work. My github repository:

https://github.com/damianjnc/lottery

I did npm install --save truffle-hdwallet-provider@0.0.3 but now got that error:

users-Air: lottery user$ node deploy.js

Attempting to deploy from account 0x14Ca642FA083121605fc860dB0024254D3FaCd61

(node:31456) UnhandledPromiseRejectionWarning: Error: Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!

at /Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-method/src/index.js:375:45

at tryCatcher (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/util.js:16:23)

at Promise._settlePromiseFromHandler (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/promise.js:497:31)

at Promise._settlePromise (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/promise.js:555:18)

at Promise._settlePromise0 (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/promise.js:600:10)

at Promise._settlePromises (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/promise.js:679:18)

at Async._drainQueue (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/async.js:125:16)

at Async._drainQueues (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/async.js:135:10)

at Immediate.Async.drainQueues (/Users/user/Documents/prod/EthereumCasts/lottery/node_modules/web3-core-promievent/node_modules/bluebird/js/release/async.js:16:14)

at runCallback (timers.js:705:18)

at tryOnImmediate (timers.js:676:5)

at processImmediate (timers.js:658:5)

(node:31456) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:31456) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

users-Air:lottery user$

Best Answer

Try installing @truffle/hdwallet-provider like this in the console (same location from where you're deploying):

npm install @truffle/hdwallet-provider

Good Luck!

Edit 2020-06-17: As of 2019-08-22, the package truffle-hdwallet-provider@1.0.17 has been deprecated and renamed to @truffle/hdwallet-provider. (Source of reference).

Related Topic