Compiling a smart contract without removing line breaks

I am new to writing a smart contract with Ethereum.

According to an official document, to compile a smart contract, you must remove all line breaks in the source code of the contract:

var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }'
var greeterCompiled = web3.eth.compile.solidity(greeterSource)

https://ethereum.gitbooks.io/frontier-guide/content/contract_greeter.html

As I think the removal process is not smart, I want to compile the code itself, for example:

var greeterCompiled = web3.eth.compile.solidity_infile( "greeter.txt" )
# The function "solidity_infile" does not exists actually, 
# but represents what I want to do.

greeter.txt

contract
mortal {
    /* Define variable owner of the type address*/
    address owner;

    /* this function is executed at initialization and sets the owner of the contract */
    function mortal() { owner = msg.sender; }

    /* Function to recover the funds on the contract */
    function kill() { if (msg.sender == owner) suicide(owner); }
}

contract greeter is mortal {
    /* define variable greeting of the type string */
    string greeting;

    /* this runs when the contract is executed */
    function greeter(string _greeting) public {
        greeting = _greeting;
    }

    /* main function */
    function greet() constant returns (string) {
        return greeting;
    }
}

Anyone how to do this?

I am using the Solidity compiler.

+4
source share
1 answer

How about downloading a contract from a file to var someContractText, and then follow these steps

someContractText = someContractText.replace(/(\r\n|\n|\r)/gm,"");
+2
source

Source: https://habr.com/ru/post/1621686/


All Articles