0

I'm trying to use truffle to deploy a smart contract onto the ethereum blockchain. There are four commands to make this happen:

truffle compile
truffle migrate --network mainnet
truffle test
truffle deploy

When on truffle migrate, I continue to get the following error:

Error: Could not create addresses from your mnemonic or private key(s). Please check that your inputs are correct.
    at new HDWalletProvider (/Users/Me/trading_bot_V2/node_modules/@truffle/hdwallet-provider/src/index.ts:119:13)
    at Object.provider (/Users/Me/trading_bot_V2/truffle-config.js:14:23)
    at Object.getProvider (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
    at Object.create (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
    at TruffleConfig.get [as provider] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:273:1)
    at Object.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:19:1)
    at runCommand (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command-utils.js:201:1)
Truffle v5.7.1 (core: 5.7.1)
Node v18.12.1

I have tried to use the mnemonic and the private key to make this work, but receive the same error. Here is the truffle-config.js file code:

require('babel-register');
require('babel-polyfill');
require("dotenv").config();
const HDWalletProvider = require("@truffle/hdwallet-provider");

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*", 
    },
    mainnet: {
      provider: () => new HDWalletProvider({
          mnemonic: process.env.MNEMONIC,
          providerOrUrl: `wss://mainnet.infura.io/ws/v3/${process.env.INFURA_API_KEY}`
      }),
      network_id: '1', 
    }
  },

  compilers: {
    solc: {
      version: '0.8.9',
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
};

Is there something I'm missing here?

To be clear, my mnemonic looks like this (this is NOT my mnemonic, just the form it takes in the .env file):

MNEMONIC="first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"

I'm really stuck here. Can't see a reason for it. Appreciate any help!

2 Answers 2

0

truffle-config.js seems to be correct. Try to put the mnemonic in .secret file and import in truffle-config file. Eg.

const HDWalletProvider = require('@truffle/hdwallet-provider');

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  contracts_build_directory: "./build/contracts",
  networks: {
    ropsten: {
      provider: () => new HDWalletProvider(mnemonic, `http://127.0.0.1:7545`),
      network_id: 5777,       // Ropsten's id
      gas: 5500000,        // Ropsten has a lower block limit than mainnet
      confirmations: 0,    // # of confirmations to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    },
  },


  // Set default mocha options here, use special reporters, etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.7",      // Fetch exact version from solc-bin (default: truffle's version)
      docker: false,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: false,
         runs: 200
       },
       evmVersion: "byzantium"
      }
    }
  },
};
1
  • Ended up with the same error. I just uninstalled and reinstalled truffle and that did the trick! Jan 24, 2023 at 9:47
0

I reinstalled truffle and that seemed to fix it.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .