我在运行我为 Solidity 项目制作的 deploy.js 文件时遇到了 assert.js:383 抛出错误我应该怎么办?

问题描述

这里是终端输出

[sohampadia@localhost inBox]$ node deploy.js 

assert.js:383

throw err;
^

AssertionError [ERR_ASSERTION]: Invalid callback object specified.
    at runWithCallbacks(/home/sohampadia/solidityprojs/inBox/node_modules/solc/wrapper.js:97:7)
    at compileStandard(/home/sohampadia/solidityprojs/inBox/node_modules/solc/wrapper.js:207:14)
    at Object.compileStandardWrapper [as compile] (/home/sohampadia/solidityprojs/inBox/node_modules/solc/wrapper.js:214:14)
    at Object.<anonymous> (/home/sohampadia/solidityprojs/inBox/compile.js:8:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/sohampadia/solidityprojs/inBox/deploy.js:3:33)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
    generatedMessage: false,code: 'ERR_ASSERTION',actual: false,expected: true,operator: '=='
}**

详情-

  • npm --version 6.14.12
  • mocha@8.3.2
  • ganache-cli@6.12.2
  • web3 // 最新版本

如果您想了解更多详情,我很乐意为您提供。

这是我的solidity文件内容

pragma solidity ^0.4.17;
contract InBox{
    string public message;
    function InBox(string initialMessage) public {
        message=initialMessage;
    }
    function setMessage(string newMessage) public{
        message=newMessage;
    }
}

这是我的 deploy.js 文件内容

const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');
const { interface,bytecode } = require('./compile');
const provider = new HDWalletProvider(
    'apple apple apple apple apple apple apple apple apple bee bee 
bee','https://rinkeby.infura.io/v3/qwertyuiopasbdhne'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts(); 
console.log('Attempting to deploy from account',accounts[0]);

const result = await new web3.eth.Contract(JSON.parse(interface))
  .deploy({ data: bytecode,arguments: ['Hi there!'] })
  .send({ gas: '1000000',from: accounts[0] }); 
console.log('Contract deployed to',result.options.address);
};
deploy();

这是我的编译(javascript)文件内容

const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inBoxPath = path.resolve(__dirname,'contracts','InBox.sol');
const source = fs.readFileSync(inBoxPath,'utf-8');
module.exports = solc.compile(source,1).contracts[':InBox'];

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)