gpt4 book ai didi

bitcoin - 编译智能合约而不删除换行符

转载 作者:行者123 更新时间:2023-12-02 10:18:26 39 4
gpt4 key购买 nike

我刚开始使用以太坊编写智能合约。

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

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。

最佳答案

如何将契约(Contract)从文件加载到 var someContractText 中,然后执行以下操作

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

关于bitcoin - 编译智能合约而不删除换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34460591/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com