【问题标题】:How to add private keys to deploy a smart contract to Roptsen?如何添加私钥以将智能合约部署到 Roptsen?
【发布时间】:2021-12-25 19:37:20
【问题描述】:

我正在尝试将智能合约部署到 Ropsten 测试网。

我曾尝试将私钥助记符添加到 .secret 文件中,但在终端中运行时出现以下错误truffle migrate --network ropsten

Error: Private key does not satisfy the curve requirements (ie. it is invalid)

infura api 密钥通过 dot env 导入来工作。

助记私钥来自元掩码钱包。

这就是现在 truffle.config 文件中的内容:

require('babel-polyfill');
require('dotenv').config();
const HDWalletProvider = require('truffle-hdwallet-provider-privkey');
const MNEMONIC = './.secret';
const infuraKey = process.env.INFURA_API_KEY


module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    },

    ropsten: {
      provider: () => new HDWalletProvider(MNEMONIC, `https://ropsten.infura.io/v3/${infuraKey}`),
      network_id: 3,       // Ropsten's id
      gas: 5500000,        // Ropsten has a lower block limit than mainnet
      confirmations: 2,    // # of confs 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 )
    }
  },
  contracts_directory: './src/contracts/',
  contracts_build_directory: './src/abis/',
  compilers: {
    solc: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  }
}

【问题讨论】:

    标签: javascript solidity web3js truffle


    【解决方案1】:

    其他人遇到了这个问题here

    有人建议先使用 Buffer.from,即Buffer.from('<PRIVATE_KEY>', 'hex') 将您的私钥转换为 Buffer。

    可以尝试以下使用:

    const privateKey = Buffer.from('PRIVATEKEYFROMMETAMASK', 'hex');
    const provider = new HDWalletProvider(privateKey, "https://ropsten.infura.io/v3/INFURATOKEN");
    const web3 = new Web3(provider);
    

    【讨论】:

      猜你喜欢
      • 2022-12-06
      • 1970-01-01
      • 2022-08-05
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2022-09-25
      相关资源
      最近更新 更多