Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 创建一个";交易处理人“;智能合约_Ethereum_Solidity_Smartcontracts - Fatal编程技术网

Ethereum 创建一个";交易处理人“;智能合约

Ethereum 创建一个";交易处理人“;智能合约,ethereum,solidity,smartcontracts,Ethereum,Solidity,Smartcontracts,刚接触solidity和geth的我开始使用solidity在线IDE和geth开发模式部署contrcts。我的问题是我尝试了几种不同的方法,但似乎没有什么真正起作用 代码: 合同交易{ 向公众所有人致辞; 映射(地址=>uint)公共余额; 函数事务(){ 所有者=msg.sender; } 函数validateTransaction(地址接收器,uint金额)常量返回(bool){ 如果(余额[所有者]uint)公共余额; //事件允许轻客户端对事件作出反应 //高效地改变。 发送的事件(

刚接触solidity和geth的我开始使用solidity在线IDE和geth开发模式部署contrcts。我的问题是我尝试了几种不同的方法,但似乎没有什么真正起作用

代码:

合同交易{
向公众所有人致辞;
映射(地址=>uint)公共余额;
函数事务(){
所有者=msg.sender;
}
函数validateTransaction(地址接收器,uint金额)常量返回(bool){
如果(余额[所有者]<金额| |所有者==接收人| |金额==0)
返回(假);
余额[所有者]-=消息值;
返回(真);
}
功能事务处理(地址接收者,uint金额){
如果(!validateTransaction(接收方,金额))
返回;
余额[接收方]+=消息值;
}
函数删除(){
如果(msg.sender==所有者)
自毁(所有者);
}
}
我也尝试过这个坚固性教程的合同,但它也没有像我预期的那样起作用:

contract Coin {
    // The keyword "public" makes those variables
    // readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react on
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    function Coin() {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        Sent(msg.sender, receiver, amount);
    }
}
合同币{
//关键字“public”使这些变量
//从外部可读。
向公众发表演说;
映射(地址=>uint)公共余额;
//事件允许轻客户端对事件作出反应
//高效地改变。
发送的事件(地址发件人、地址收件人、uint金额);
//这是其代码为的构造函数
//仅在创建合同时运行。
功能币(){
minter=msg.sender;
}
功能造币厂(地址接收者,单位金额){
如果(msg.sender!=minter)返回;
余额[接收方]+=金额;
}
函数发送(地址接收器,uint金额){
if(余额[msg.sender]<金额)返回;
余额[消息发送方]-=金额;
余额[接收方]+=金额;
已发送(消息发送方、接收方、金额);
}
}

我只是想做一个智能合约,可以让发送者和接收者之间进行交易,但账户余额不会移动。这些函数仅仅是为了了解坚固性是如何工作的,还是这真的能改变平衡?感谢您的回答:)

在对solidity进行了深入的搜索和研究之后,我发现,事实上,该合同将抽象事务转换为他的数据。因此,乙醚并不是真正发送的,平衡变量是本合同的局部变量

contract Coin {
    // The keyword "public" makes those variables
    // readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react on
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    function Coin() {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        Sent(msg.sender, receiver, amount);
    }
}