0

I am new to solidity . I am trying to build some smart contracts following a course . I have my "compile.js" file .When I run it using the command "node compile.js ",then it shows the error

"Range error :Maximum call stack size exceeded" .

But when I run the command

"node --stack-size=2000 compile.js"

then I get the bytecode and abi of my contract .I need bytecode generated from compile.js file to another file, until I fix this error it seems not to work.

I saw my node version has the stack size =984 . Is there any solution so that I can fix my stack size to 2000 or is there any node js version which has already 2000 default stack size or can I put any code in my contract so that stack size remain 2000 .

I tried many solutions

const v8 = require('v8'); v8.setFlagsFromString('--stack-size=2000');

I put this in my compile.js file .but it seems not to work .Thanks a lot .

here is my compile.js file

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

const solc=require('solc');

const v8 = require('v8');
v8.setFlagsFromString('--stack-size=2000');

const inboxPath=path.resolve(__dirname,'contracts','Inbox.sol');

const source = fs.readFileSync(inboxPath,'utf-8');

module.exports = solc.compile(source,1).contracts[':Inbox'];

here is my main smart contract

pragma solidity >=0.4.25;

contract Inbox {
    string public message;

    constructor(string memory intialmsg) public{
        message = intialmsg;
    }

    function setmessage(string memory newMessage) public {
        message = newMessage;
    }
}

I checked my solc version and solidity version and both seems same : here is package.json file

{
  "name": "inbox",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ganache-cli": "^6.12.2",
    "mocha": "^10.2.0",
    "openzeppelin-solidity": "^4.6.0",
    "solc": "^0.4.25",
    "web3": "^1.0.0-beta.26"
  }
}

I have been struggling with this problem for so long ,dont want to quit here .Thanks a lot .

1 Answer 1

0

You could try this, to reinstall the node modules. The contract is not so big to cause problems while compiling.

rm -rf node_modules && rm package-lock.json
npm cache clean --force
npm install

Also check with the versions of ganache and web3.js . The version of web3 you're currently using seems to be in beta.

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.