I'm using the solc module to compile a Solidity contract. The compilation step looks to be working correctly, however, when I attempt to deploy the contract to the Ganache network (in a Mocha test), the promise never resolves. Here's what I've already checked:

1) Increasing the timeout to 3 minutes - still nothing

2) Another promise using await, which resolved correctly, so I don't think it's a Mocha config issue with promises

3) Estimated gas - I should have more than enough based on the estimateGas function

4) Updating all versions (web3, solc, ganache-cli) to their most recent versions

Here's the compile.js code:

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const contractPath = path.resolve(__dirname, 'MyContract.sol');
const source = fs.readFileSync(contractPath, 'utf8');

let jsonContractSource = JSON.stringify({
    language: 'Solidity',
    sources: {
      'Task': {
          content: source,
    settings: { 
        outputSelection: {
            '*': {
                '*': ['abi',"evm.bytecode"],   
             // here point out the output of the compiled result

module.exports = JSON.parse(solc.compile(jsonContractSource)).contracts.Task.MyContract;

And the test file:

const ganache = require('ganache-cli');
const Web3 = require('web3');
const provider = ganache.provider()
const web3 = new Web3(provider);
const { abi, evm } = require('../../contracts/compile');

let accounts;
let myContract;

before(async function() {

    accounts = await web3.eth.getAccounts()

    myContract = await new web3.eth.Contract(abi)
        .deploy({data: "0x" + evm.bytecode.object, arguments: []})
        .send({from: accounts[0], gas: 5000000});



EDIT: One other thing - I was able to deploy a contract to the Ganache network with Remix, so I think the problem is isolated to the ganache-cli.

  • What version of solc are you using? Also, when you say 'you were able to deploy a contract to the Ganache network in remix'. I did not understand this. are you refering to the Javascript VM or using Metamask you injected your local ganache network?
    – Sanjay S B
    Commented May 31, 2019 at 8:04
  • I was/am using the latest version of solc. I believe I had to in order to use Solidity 0.5. I was able to connect to the Ganache network by going to Environment > Web3 Provider and entering the localhost address for the Ganache network. I was able to deploy a contract and the related address balance decreased in the Ganache console, which is how I knew it was successful. Commented May 31, 2019 at 17:35

2 Answers 2


Found the answer. It turns out that the web3 options aren't exactly optional for Ganache:

I had to change:

const provider = ganache.provider()
const web3 = new Web3(provider);


const provider = ganache.provider()
const OPTIONS = {
  defaultBlock: "latest",
  transactionConfirmationBlocks: 1,
  transactionBlockTimeout: 5
const web3 = new Web3(provider, null, OPTIONS);

I believe that if there are no it parts, then the before part is simply not executed.

You can verify this by adding to your script, for example:

it("test", async function() {
  • Sorry for the confusion - I have it statements, but I left them out for brevity. Commented May 31, 2019 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.