1

我的实习生刚接触solidity 和geth,我开始使用solidity 在线IDE 和geth 开发模式部署contrcts。我的问题是我尝试了几种不同的方法,但似乎没有任何效果。

代码:

contract Transaction {
  address public owner;
  mapping (address => uint) public balances;

  function Transaction () {
      owner = msg.sender;
  }

  function validateTransaction (address receiver, uint amount) constant returns (bool) {
    if  (balances[owner] < amount || owner == receiver || amount == 0)
        return (false);
    balances[owner] -= msg.value;
    return (true);
  }

  function transact (address receiver, uint amount) {
    if (!validateTransaction(receiver, amount))
        return ;
    balances[receiver] += msg.value;
  }

  function remove () {
      if (msg.sender == owner)
        selfdestruct(owner);
  }
}

我也尝试了这个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);
    }
}

我只是想制作一个智能合约,可以在发送方和接收方之间进行交易,但账户余额不会移动。这些功能是否只是抽象的,以了解 Solidity 的工作原理,还是这真的可以改变平衡?感谢您的回答:)

4

1 回答 1

1

在搜索并深入研究solidity 后,我发现该合约确实将抽象交易纳入HIS 数据。所以以太币并没有真正被发送,并且余额变量是这个合约的本地变量。

于 2016-07-20T16:31:31.853 回答