10 truffle 配置BSC测试网部署报错

我的配置如下,已执行安装npm install truffle-hdwallet-provider -g,执行truffle migrate --network bsctest时报错提示ReferenceError: HDWalletProvider is not defined

module.exports = {
  networks: {
    bsctest: {
      provider: function() {
        return new HDWalletProvider(mnemonic, "https://data-seed-prebsc-1-s1.binance.org:8545/")
      },
      network_id: 97,
      gasPrice: 5000000000,
    },
  },
  mocha: {
    // timeout: 100000
  },
  compilers: {
    solc: {
    }
  }
};

报错信息:

wangwei@wangweidembp greeting % truffle migrate --network bsctest

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

ReferenceError: HDWalletProvider is not defined
    at Object.provider (/Users/wangwei/Workspace/blockchain/ETH/greeting/truffle-config.js:6:9)
    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:204:1)
    at Object.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:206:1
Truffle v5.1.60 (core: 5.1.60)
Node v14.15.1
请先 登录 后评论

最佳答案 2021-05-19 09:31

在 truffle-cofig.js 的开头, 加 const HDWalletProvider = require('truffle-hdwallet-provider');

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 1 收藏,4291 浏览
  • wangwei123 提出于 2021-05-18 14:16