Solidity compiler - problem with HelloWorld smart contract












0















Im trying to run my first HelloWorld smart contract on the Enthereum network. This is my HelloWorld.sol contract.



pragma solidity ^0.5.0;

contract HelloWorld {
bytes32 message;
constructor (bytes32 myMessage) public {
message = myMessage;
}
function getMessage() public returns(bytes32) {
return message;
}
}


When I try to build this using solcjs HelloWorld.sol --bin, there is just one Warning and no errors. I have installed web3 and solc using npm. When I run this on a node



var solc = require('solc');
var x = fs.readFileSync('./HelloWorld.sol').toString();
var compiledContract = solc.compile(x);


the compiledContractcontains this:



'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","message":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","severity":"error","type":"JSONError"}]}'


Where is the problem?










share|improve this question























  • Can you try with an earlier version of the solidity compiler?

    – nikos fotiadis
    Nov 24 '18 at 20:28











  • If I write pragma solidity ^0.4.x it throws error that I have version 0.5.0

    – Banana Cake
    Nov 24 '18 at 21:23











  • I think you need to change the version of the compiler you have installed as well.

    – nikos fotiadis
    Nov 24 '18 at 21:34











  • I changed the version to 0.4.18 but there is the same problem.

    – Banana Cake
    Nov 24 '18 at 22:39
















0















Im trying to run my first HelloWorld smart contract on the Enthereum network. This is my HelloWorld.sol contract.



pragma solidity ^0.5.0;

contract HelloWorld {
bytes32 message;
constructor (bytes32 myMessage) public {
message = myMessage;
}
function getMessage() public returns(bytes32) {
return message;
}
}


When I try to build this using solcjs HelloWorld.sol --bin, there is just one Warning and no errors. I have installed web3 and solc using npm. When I run this on a node



var solc = require('solc');
var x = fs.readFileSync('./HelloWorld.sol').toString();
var compiledContract = solc.compile(x);


the compiledContractcontains this:



'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","message":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","severity":"error","type":"JSONError"}]}'


Where is the problem?










share|improve this question























  • Can you try with an earlier version of the solidity compiler?

    – nikos fotiadis
    Nov 24 '18 at 20:28











  • If I write pragma solidity ^0.4.x it throws error that I have version 0.5.0

    – Banana Cake
    Nov 24 '18 at 21:23











  • I think you need to change the version of the compiler you have installed as well.

    – nikos fotiadis
    Nov 24 '18 at 21:34











  • I changed the version to 0.4.18 but there is the same problem.

    – Banana Cake
    Nov 24 '18 at 22:39














0












0








0


1






Im trying to run my first HelloWorld smart contract on the Enthereum network. This is my HelloWorld.sol contract.



pragma solidity ^0.5.0;

contract HelloWorld {
bytes32 message;
constructor (bytes32 myMessage) public {
message = myMessage;
}
function getMessage() public returns(bytes32) {
return message;
}
}


When I try to build this using solcjs HelloWorld.sol --bin, there is just one Warning and no errors. I have installed web3 and solc using npm. When I run this on a node



var solc = require('solc');
var x = fs.readFileSync('./HelloWorld.sol').toString();
var compiledContract = solc.compile(x);


the compiledContractcontains this:



'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","message":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","severity":"error","type":"JSONError"}]}'


Where is the problem?










share|improve this question














Im trying to run my first HelloWorld smart contract on the Enthereum network. This is my HelloWorld.sol contract.



pragma solidity ^0.5.0;

contract HelloWorld {
bytes32 message;
constructor (bytes32 myMessage) public {
message = myMessage;
}
function getMessage() public returns(bytes32) {
return message;
}
}


When I try to build this using solcjs HelloWorld.sol --bin, there is just one Warning and no errors. I have installed web3 and solc using npm. When I run this on a node



var solc = require('solc');
var x = fs.readFileSync('./HelloWorld.sol').toString();
var compiledContract = solc.compile(x);


the compiledContractcontains this:



'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","message":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 2\n  Extra non-whitespace after JSON value.\n","severity":"error","type":"JSONError"}]}'


Where is the problem?







node.js ethereum solidity smartcontracts






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 18:10









Banana CakeBanana Cake

909




909













  • Can you try with an earlier version of the solidity compiler?

    – nikos fotiadis
    Nov 24 '18 at 20:28











  • If I write pragma solidity ^0.4.x it throws error that I have version 0.5.0

    – Banana Cake
    Nov 24 '18 at 21:23











  • I think you need to change the version of the compiler you have installed as well.

    – nikos fotiadis
    Nov 24 '18 at 21:34











  • I changed the version to 0.4.18 but there is the same problem.

    – Banana Cake
    Nov 24 '18 at 22:39



















  • Can you try with an earlier version of the solidity compiler?

    – nikos fotiadis
    Nov 24 '18 at 20:28











  • If I write pragma solidity ^0.4.x it throws error that I have version 0.5.0

    – Banana Cake
    Nov 24 '18 at 21:23











  • I think you need to change the version of the compiler you have installed as well.

    – nikos fotiadis
    Nov 24 '18 at 21:34











  • I changed the version to 0.4.18 but there is the same problem.

    – Banana Cake
    Nov 24 '18 at 22:39

















Can you try with an earlier version of the solidity compiler?

– nikos fotiadis
Nov 24 '18 at 20:28





Can you try with an earlier version of the solidity compiler?

– nikos fotiadis
Nov 24 '18 at 20:28













If I write pragma solidity ^0.4.x it throws error that I have version 0.5.0

– Banana Cake
Nov 24 '18 at 21:23





If I write pragma solidity ^0.4.x it throws error that I have version 0.5.0

– Banana Cake
Nov 24 '18 at 21:23













I think you need to change the version of the compiler you have installed as well.

– nikos fotiadis
Nov 24 '18 at 21:34





I think you need to change the version of the compiler you have installed as well.

– nikos fotiadis
Nov 24 '18 at 21:34













I changed the version to 0.4.18 but there is the same problem.

– Banana Cake
Nov 24 '18 at 22:39





I changed the version to 0.4.18 but there is the same problem.

– Banana Cake
Nov 24 '18 at 22:39












1 Answer
1






active

oldest

votes


















1














The problem was, that you I can not put raw solidity smart contract into solc.compile() function. There must be Compiler Standard Input JSON. Based on my another thread I found this solution:



> var Web3 = require('web3');
> var solc = require('solc');
> var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
> var CONTRACT_FILE = 'HelloWorld.sol'
> var content =fs.readFileSync(CONTRACT_FILE).toString()
> var input = {
language: 'Solidity',
sources: {
[CONTRACT_FILE]: {
content: content
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
}

> var compiled = solc.compile(JSON.stringify(input))
> var output = JSON.parse(compiled)
> var abi = output.contracts[CONTRACT_FILE]['HelloWorld'].abi
> var bytecode = output.contracts[CONTRACT_FILE]['HelloWorld'].evm.bytecode.object
> var HelloWorld = new web3.eth.Contract(abi);
> var HelloWorldTx = HelloWorld.deploy({data: bytecode, arguments: [web3.utils.asciiToHex('Hello')]});
> web3.eth.estimateGas(HelloWorldTx).then(console.log); //this does not work, because it can not connect to the localhost:8545. I don't know why.
> HelloWorldTx.send({from: '0x99d54a45f2cd3b9c6443d623003416aaf944338e', gas: 1000000}).then(console.log);





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461034%2fsolidity-compiler-problem-with-helloworld-smart-contract%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The problem was, that you I can not put raw solidity smart contract into solc.compile() function. There must be Compiler Standard Input JSON. Based on my another thread I found this solution:



    > var Web3 = require('web3');
    > var solc = require('solc');
    > var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
    > var CONTRACT_FILE = 'HelloWorld.sol'
    > var content =fs.readFileSync(CONTRACT_FILE).toString()
    > var input = {
    language: 'Solidity',
    sources: {
    [CONTRACT_FILE]: {
    content: content
    }
    },
    settings: {
    outputSelection: {
    '*': {
    '*': ['*']
    }
    }
    }
    }

    > var compiled = solc.compile(JSON.stringify(input))
    > var output = JSON.parse(compiled)
    > var abi = output.contracts[CONTRACT_FILE]['HelloWorld'].abi
    > var bytecode = output.contracts[CONTRACT_FILE]['HelloWorld'].evm.bytecode.object
    > var HelloWorld = new web3.eth.Contract(abi);
    > var HelloWorldTx = HelloWorld.deploy({data: bytecode, arguments: [web3.utils.asciiToHex('Hello')]});
    > web3.eth.estimateGas(HelloWorldTx).then(console.log); //this does not work, because it can not connect to the localhost:8545. I don't know why.
    > HelloWorldTx.send({from: '0x99d54a45f2cd3b9c6443d623003416aaf944338e', gas: 1000000}).then(console.log);





    share|improve this answer






























      1














      The problem was, that you I can not put raw solidity smart contract into solc.compile() function. There must be Compiler Standard Input JSON. Based on my another thread I found this solution:



      > var Web3 = require('web3');
      > var solc = require('solc');
      > var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
      > var CONTRACT_FILE = 'HelloWorld.sol'
      > var content =fs.readFileSync(CONTRACT_FILE).toString()
      > var input = {
      language: 'Solidity',
      sources: {
      [CONTRACT_FILE]: {
      content: content
      }
      },
      settings: {
      outputSelection: {
      '*': {
      '*': ['*']
      }
      }
      }
      }

      > var compiled = solc.compile(JSON.stringify(input))
      > var output = JSON.parse(compiled)
      > var abi = output.contracts[CONTRACT_FILE]['HelloWorld'].abi
      > var bytecode = output.contracts[CONTRACT_FILE]['HelloWorld'].evm.bytecode.object
      > var HelloWorld = new web3.eth.Contract(abi);
      > var HelloWorldTx = HelloWorld.deploy({data: bytecode, arguments: [web3.utils.asciiToHex('Hello')]});
      > web3.eth.estimateGas(HelloWorldTx).then(console.log); //this does not work, because it can not connect to the localhost:8545. I don't know why.
      > HelloWorldTx.send({from: '0x99d54a45f2cd3b9c6443d623003416aaf944338e', gas: 1000000}).then(console.log);





      share|improve this answer




























        1












        1








        1







        The problem was, that you I can not put raw solidity smart contract into solc.compile() function. There must be Compiler Standard Input JSON. Based on my another thread I found this solution:



        > var Web3 = require('web3');
        > var solc = require('solc');
        > var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
        > var CONTRACT_FILE = 'HelloWorld.sol'
        > var content =fs.readFileSync(CONTRACT_FILE).toString()
        > var input = {
        language: 'Solidity',
        sources: {
        [CONTRACT_FILE]: {
        content: content
        }
        },
        settings: {
        outputSelection: {
        '*': {
        '*': ['*']
        }
        }
        }
        }

        > var compiled = solc.compile(JSON.stringify(input))
        > var output = JSON.parse(compiled)
        > var abi = output.contracts[CONTRACT_FILE]['HelloWorld'].abi
        > var bytecode = output.contracts[CONTRACT_FILE]['HelloWorld'].evm.bytecode.object
        > var HelloWorld = new web3.eth.Contract(abi);
        > var HelloWorldTx = HelloWorld.deploy({data: bytecode, arguments: [web3.utils.asciiToHex('Hello')]});
        > web3.eth.estimateGas(HelloWorldTx).then(console.log); //this does not work, because it can not connect to the localhost:8545. I don't know why.
        > HelloWorldTx.send({from: '0x99d54a45f2cd3b9c6443d623003416aaf944338e', gas: 1000000}).then(console.log);





        share|improve this answer















        The problem was, that you I can not put raw solidity smart contract into solc.compile() function. There must be Compiler Standard Input JSON. Based on my another thread I found this solution:



        > var Web3 = require('web3');
        > var solc = require('solc');
        > var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
        > var CONTRACT_FILE = 'HelloWorld.sol'
        > var content =fs.readFileSync(CONTRACT_FILE).toString()
        > var input = {
        language: 'Solidity',
        sources: {
        [CONTRACT_FILE]: {
        content: content
        }
        },
        settings: {
        outputSelection: {
        '*': {
        '*': ['*']
        }
        }
        }
        }

        > var compiled = solc.compile(JSON.stringify(input))
        > var output = JSON.parse(compiled)
        > var abi = output.contracts[CONTRACT_FILE]['HelloWorld'].abi
        > var bytecode = output.contracts[CONTRACT_FILE]['HelloWorld'].evm.bytecode.object
        > var HelloWorld = new web3.eth.Contract(abi);
        > var HelloWorldTx = HelloWorld.deploy({data: bytecode, arguments: [web3.utils.asciiToHex('Hello')]});
        > web3.eth.estimateGas(HelloWorldTx).then(console.log); //this does not work, because it can not connect to the localhost:8545. I don't know why.
        > HelloWorldTx.send({from: '0x99d54a45f2cd3b9c6443d623003416aaf944338e', gas: 1000000}).then(console.log);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 16 '18 at 17:55

























        answered Dec 16 '18 at 17:35









        Banana CakeBanana Cake

        909




        909
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461034%2fsolidity-compiler-problem-with-helloworld-smart-contract%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python