1

I'm having difficulty deploying a solc-compiled contract to ganache test network using web3.

package.json

{
  "name": "smartinvoice",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "node ethereum/compile.js && mocha"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "solc": "^0.5.6",
    "web3": "^1.0.0-beta.50"
  },
  "devDependencies": {
    "ganache-cli": "^6.4.1",
    "mocha": "^6.0.2"
  }
}

SmartInvoice.sol

pragma solidity ^0.5.6;

contract SmartInvoiceFactory {}

compile.js

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

const buildPath = path.resolve(__dirname, 'build');
fs.removeSync(buildPath)

const sourceFilename = 'SmartInvoice.sol';
const sourcePath = path.resolve(__dirname, 'contracts', sourceFilename);
const content = fs.readFileSync(sourcePath, 'utf8');

const input = {
    language: 'Solidity',
    sources: {
        [sourceFilename]: {
            content
        }
    },
    settings: {
        outputSelection: {
            '*': {
                '*': [ '*' ]
            }
        }
    }
}

var output = JSON.parse(solc.compile(JSON.stringify(input)))

for (var contract in output.contracts[sourceFilename]) {
    fs.outputJsonSync(
        path.resolve(buildPath, contract + '.json'),
        output.contracts[sourceFilename][contract]
    )
}

The issue I have is when I run my tests:

SmartInvoice.test.js

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const provider = ganache.provider();
const web3 = new Web3(provider);

const compiledSmartInvoiceFactory = require('../ethereum/build/SmartInvoiceFactory.json');

let accounts;
let smartInvoiceFactory;

beforeEach(async () => {
    accounts = await web3.eth.getAccounts();

    let superuser = accounts[0];

    smartInvoiceFactory = await new web3.eth.Contract(compiledSmartInvoiceFactory.abi)
        .deploy({
            data: compiledSmartInvoiceFactory.evm.bytecode.object
        })
        .send({
            from: superuser,
            gas: '1000000'
        });

});

describe('Testing setup', () => {
    it('deploys a smart invoice factory', () => {
        assert.ok(smartInvoiceFactory.options.address);
    });
});

And the error I'm getting is:

 0 passing (1s)
  1 failing

  1) "before each" hook for "deploys a smart invoice factory":
     Error: Transaction has been reverted by the EVM:
{
  "transactionHash": "0x6b80cffe924704ef1b5ac3df34b962cd8409c687b2650d85160507cf9b9315cf",
  "transactionIndex": 0,
  "blockHash": "0x257517e61c28756fc36b5ee171761058f8d0b7dd3f540e9a5f5bfa2ba139cd18",
  "blockNumber": 1,
  "from": "0xdbe75311f72765d33a1fcc9b36ae8c13e430a5ea",
  "to": null,
  "gasUsed": 68922,
  "cumulativeGasUsed": 68922,
  "contractAddress": "0xe82e8C65a8F4c4b705d8309Fb61338c6AedA3Fc4",
  "logs": [],
  "status": true,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "v": "0x1b",
  "r": "0xf3df3474ed79d2bab6b46b15c14109668336d12c69c086bdbd42b2c8bf66cc5b",
  "s": "0x314faba76199531fb4cc19a9202aadd4614c6aea632886570f8949fa002f8924"
}
      at SafeSubscriber._next (node_modules/web3-core-method/dist/web3-core-method.cjs.js:1017:32)
      at SafeSubscriber.__tryOrUnsub (node_modules/rxjs/src/internal/Subscriber.ts:267:10)
      at SafeSubscriber.next (node_modules/rxjs/src/internal/Subscriber.ts:209:14)
      at Subscriber._next (node_modules/rxjs/src/internal/Subscriber.ts:139:22)
      at Subscriber.next (node_modules/rxjs/src/internal/Subscriber.ts:99:12)
      at TransactionObserver.emitNext (node_modules/web3-core-method/dist/web3-core-method.cjs.js:438:16)
      at _callee2$ (node_modules/web3-core-method/dist/web3-core-method.cjs.js:408:24)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at process._tickCallback (internal/process/next_tick.js:68:7)

Any help very much appreciated. Thank you.

EDIT:

SmartInvoiceFactory.json

{"abi":[],"devdoc":{"methods":{}},"evm":{"assembly":"    /* \"SmartInvoice.sol\":25:488  contract SmartInvoiceFactory {... */\n  mstore(0x40, 0x80)\n  callvalue\n    /* \"--CODEGEN--\":8:17   */\n  dup1\n    /* \"--CODEGEN--\":5:7   */\n  iszero\n  tag_1\n  jumpi\n    /* \"--CODEGEN--\":30:31   */\n  0x00\n    /* \"--CODEGEN--\":27:28   */\n  dup1\n    /* \"--CODEGEN--\":20:32   */\n  revert\n    /* \"--CODEGEN--\":5:7   */\ntag_1:\n    /* \"SmartInvoice.sol\":25:488  contract SmartInvoiceFactory {... */\n  pop\n  dataSize(sub_0)\n  dup1\n  dataOffset(sub_0)\n  0x00\n  codecopy\n  0x00\n  return\nstop\n\nsub_0: assembly {\n        /* \"SmartInvoice.sol\":25:488  contract SmartInvoiceFactory {... */\n      mstore(0x40, 0x80)\n      0x00\n      dup1\n      revert\n\n    auxdata: 0xa165627a7a723058208bbe0c0623dde54610c2c909e36e041feb3e7b3cd6738c4882df7cec61d1ad660029\n}\n","bytecode":{"linkReferences":{},"object":"6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfea165627a7a723058208bbe0c0623dde54610c2c909e36e041feb3e7b3cd6738c4882df7cec61d1ad660029","opcodes":"PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x35 DUP1 PUSH1 0x1D PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG1 PUSH6 0x627A7A723058 KECCAK256 DUP12 0xbe 0xc MOD 0x23 0xdd 0xe5 0x46 LT 0xc2 0xc9 MULMOD 0xe3 PUSH15 0x41FEB3E7B3CD6738C4882DF7CEC61 0xd1 0xad PUSH7 0x290000000000 ","sourceMap":"25:463:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;25:463:0;;;;;;;"},"deployedBytecode":{"linkReferences":{},"object":"6080604052600080fdfea165627a7a723058208bbe0c0623dde54610c2c909e36e041feb3e7b3cd6738c4882df7cec61d1ad660029","opcodes":"PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG1 PUSH6 0x627A7A723058 KECCAK256 DUP12 0xbe 0xc MOD 0x23 0xdd 0xe5 0x46 LT 0xc2 0xc9 MULMOD 0xe3 PUSH15 0x41FEB3E7B3CD6738C4882DF7CEC61 0xd1 0xad PUSH7 0x290000000000 ","sourceMap":"25:463:0:-;;;;;"},"gasEstimates":{"creation":{"codeDepositCost":"10600","executionCost":"66","totalCost":"10666"}},"legacyAssembly":{".code":[{"begin":25,"end":488,"name":"PUSH","value":"80"},{"begin":25,"end":488,"name":"PUSH","value":"40"},{"begin":25,"end":488,"name":"MSTORE"},{"begin":25,"end":488,"name":"CALLVALUE"},{"begin":8,"end":17,"name":"DUP1"},{"begin":5,"end":7,"name":"ISZERO"},{"begin":5,"end":7,"name":"PUSH [tag]","value":"1"},{"begin":5,"end":7,"name":"JUMPI"},{"begin":30,"end":31,"name":"PUSH","value":"0"},{"begin":27,"end":28,"name":"DUP1"},{"begin":20,"end":32,"name":"REVERT"},{"begin":5,"end":7,"name":"tag","value":"1"},{"begin":5,"end":7,"name":"JUMPDEST"},{"begin":25,"end":488,"name":"POP"},{"begin":25,"end":488,"name":"PUSH #[$]","value":"0000000000000000000000000000000000000000000000000000000000000000"},{"begin":25,"end":488,"name":"DUP1"},{"begin":25,"end":488,"name":"PUSH [$]","value":"0000000000000000000000000000000000000000000000000000000000000000"},{"begin":25,"end":488,"name":"PUSH","value":"0"},{"begin":25,"end":488,"name":"CODECOPY"},{"begin":25,"end":488,"name":"PUSH","value":"0"},{"begin":25,"end":488,"name":"RETURN"}],".data":{"0":{".auxdata":"a165627a7a723058208bbe0c0623dde54610c2c909e36e041feb3e7b3cd6738c4882df7cec61d1ad660029",".code":[{"begin":25,"end":488,"name":"PUSH","value":"80"},{"begin":25,"end":488,"name":"PUSH","value":"40"},{"begin":25,"end":488,"name":"MSTORE"},{"begin":25,"end":488,"name":"PUSH","value":"0"},{"begin":25,"end":488,"name":"DUP1"},{"begin":25,"end":488,"name":"REVERT"}]}}},"methodIdentifiers":{}},"metadata":"{\"compiler\":{\"version\":\"0.5.6+commit.b259423e\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"SmartInvoice.sol\":\"SmartInvoiceFactory\"},\"evmVersion\":\"petersburg\",\"libraries\":{},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"SmartInvoice.sol\":{\"keccak256\":\"0xac17b72cd66b0df5e56961a5fff9995d429e0563be78a56b6e051bd32ed49734\",\"urls\":[\"bzzr://29a74deb0ff4e8294835359383bf8530d3a07fdd996e32abf6167a7e3e91d12f\"]}},\"version\":1}","userdoc":{"methods":{}}}
  • can you show SmartInvoiceFactory.json file contents once generated. – Abdullah Aziz Mar 26 at 1:25
0

You need to update Web3 API implementation. The one you are using does not fully support Bysantium. See answer here: could not be able to change my setmessage because (Transaction has been reverted by the EVM:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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