truffle初始化的项目在部署(migrate)的时候出现invalid opcode的异常

异常重现

最近在使用truffle框架与Ganache开发以太坊合约的时候,采用默认配置的时候(仅修改端口为7545),部署时会出现invalid opcode异常如下图:
异常截图

项目初始化

通过命令truffle unbox webpack进行项目初始化
项目目录如下:
项目目录

配置文件truffle-config.js详情

/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * truffleframework.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura accounts
 * are available for free at: infura.io/register.
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

// const HDWallet = require('truffle-hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
您好!感谢您的提问!来自 C 知道的我将为您解答关于使用 Truffle 部署合约的问题。 要使用 Truffle 部署合约,您可以按照以下步骤进行操作: 1. 首先,确保您已经在您的项目中安装了 Truffle。如果没有安装,可以通过运行以下命令进行安装: ``` npm install -g truffle ``` 2. 确保您已经在项目目录中初始化Truffle,可以通过运行以下命令完成初始化: ``` truffle init ``` 3. 在项目目录中,您需要在 `contracts` 文件夹中编写您的智能合约代码。例如,您可以创建一个名为 `MyContract.sol` 的文件,并编写您的合约代码。 4. 在部署合约之前,您需要配置 Truffle 的网络设置。打开项目目录中的 `truffle-config.js`(或 `truffle.js`,取决于您的项目版本),并根据需要配置网络。例如,您可以添加一个名为 "development" 的网络配置: ```javascript module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", } }, }; ``` 5. 在部署之前,您可以通过运行以下命令来编译您的合约: ``` truffle compile ``` 6. 最后,您可以使用以下命令来部署合约: ``` truffle migrate --network development ``` 上述命令将在您配置的 "development" 网络上部署合约。如果您配置了其他网络,请相应地更改命令中的网络名称。 这就是使用 Truffle 部署合约的基本步骤。希望能对您有所帮助!如果您有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值