比特币 – 在不删除换行符的情况下编译智能合约

我很想和以太坊签一份智能合约.

根据官方文档,编译智能合约需要删除合同源代码中的所有换行符:

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

我认为删除过程并不聪明,我想编译代码本身,如:

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;
    }
}

有人怎么做?

我正在使用的编译器是Solidity.

最佳答案 如何将合同从文件加载到var someContractText然后执行以下操作

someContractText = someContractText.replace(/(\r\n|\n|\r)/gm,"");
点赞