1

私は 2 つの基本契約を持っています。1 つはトークン用で、もう 1 つは販売用です。

トークン契約:

contract MyToken is StandardToken, Ownable {

    string public constant name = "My Sample Token";

    string public constant symbol = "MST";

    uint32 public constant decimals = 18;

    function MyToken(uint _totalSupply) {
       require (_totalSupply > 0);
       totalSupply = _totalSupply;
       balances[msg.sender] = totalSupply;
    }
}

売買契約書

contract Sale {
    address owner;

    address public founderAddress;
    uint256 public constant foundersAmount = 50;

    MyToken public token = new MyToken(1000);


    uint256 public issuedTokensAmount = 0;

    function Sale() {
        owner = msg.sender;
        founderAddress = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c;
        token.transfer(founderAddress, foundersAmount);
    }

    function() external payable {
        token.transfer(msg.sender, 1);
        owner.transfer(msg.value);
    }   
}

StandardTokenOwnableはすべて、OpenZeppelin リポジトリの標準実装です。完全な契約ソースはこちらから入手できます。

So basically in my Sale Contract I create an instance of my token contract with fixed supply and assign all of the tokens to the caller. Then I transfer some amount of tokens to founder address. When I try to send some ethereum to Sale contract I'm attempting to transfer some of my tokens to the sender (Running all code in Remix browser, I create an instance of Sale contract and call "fallback" method specifying some ether amount). However, this fails with "Exception during execution. (invalid opcode). Please debug the transaction for more information." message. All that I can see when debugging is that code fails in payable method at line:

 token.transfer(msg.sender, 1);

I can't see the exact reason for this as I'm not able to step into this method and see whats going on inside.

興味深いことに、Sale Contract コンストラクターのトークン インスタンスで transfer メソッドの呼び出しを削除すると、コードは例外なく正常に動作するように見えます。

私は何が欠けていますか?

4

2 に答える 2