我很高兴与以太坊签订智能合约。
根据官方文件,编制智能合约需要删除合同源代码中的所有换行符:
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
由于我认为删除过程不是 smart ,我想编译代码本身,如:
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。
答案 0 :(得分:2)
如何将合同从文件加载到var someContractText
,然后执行以下操作
someContractText = someContractText.replace(/(\r\n|\n|\r)/gm,"");