3

I am a new comer to the Ethereum and I am writing a piece of smart contract for my project. I used Win 10 and Mist 0.8.8 with the testnet that started with "R".

The contract code has the functions of changing the state and some modifier, however, after I launched the contract, I am not able to run any functions of it. The following errors show up. Thank you so much!!!

enter image description here enter image description here

The contract code is show below: Thank you so much!

pragma solidity ^0.4.6;
contract FairTrade {

    /* Variables */
    address public creater;
    address public trader;
    address public framer;
    address public preieumHandler;

    /* State handling */
    enum State { Paying, Transporting, Received, Completed }
    State public state;

    /* Contructor */
    function FairTrade(address _trader, address _framer, address _preieumHandler,
      uint _price, uint _quantity) {
        creater = msg.sender;
        trader = _trader;
        framer = _framer;
        preieumHandler = _preieumHandler;

    }

    /* Modifiers */    
    modifier onlyFramer {
        if (msg.sender != framer) throw ; else _;
    }

    modifier onlyTrader {
        if (msg.sender != trader) throw; else _;
    }

    modifier inState(State s) {
        if (state != s) throw; else _;
    }

    modifier notInState(State s) {
        if (state == s) throw; else _;
    }

    /* Functions */    
    function completedPaid() onlyTrader {
        state = State.Transporting;
    }    

    function receivedGood() inState(State.Transporting) onlyFramer {
        state = State.Received;
    }

    function paid() inState(State.Received) {
        state = State.Completed;
    }
}

1 Answer 1

2

The Testnet has the name Ropsten.

From the raw data 0x295b4e17 in your first image, you are trying to execute the paid() function.

I checked each of the function signatures in the geth command line and the following signature matched:

> web3.sha3("paid()").substring(0, 10)
"0x295b4e17"

This paid() function has the modifier inState(State.Received) and this modifier will throw an error is the current state variable is NOT State.Received.

The warning you are being show is because Mist simulates the call you are attempting to execute and has determined that the call the paid() will fail as the current state variable is not set to State.Received.

To test out your functionality, you could either:

  1. Add other function(s) to move your workflow state to State.Received; or

  2. Remove the inState(State.Received) modifier from the paid() function.

I would suggest firstly trying 2. above so you can determine whether you can execute the paid() function successfully. Once you have confirmed that the paid() function without the modifier executes successfully, create the other require functions to move your contract state to State.Received when paid() with your modifier will work.



Update Responding To Comment Below

Q: Should I use uint to be the type of variable to record ehter send?

A: uint (which is uint256) is suitable for recording the number of ethers.

Q: When I send 1 Ether to the contract, it shows 1000000000 wai instead.

A: 1 ether is 1e18 or 1,000,000,000,000,000,000 weis. In geth:

> 1e18
1000000000000000000
> web3.fromWei(1e18,"ether")
"1"
> web3.toWei(1,"ether")
"1000000000000000000"

Q: Finally, I would like to learn the cml to run the contract. Do you have some recommended link for me?

A: If cml refers to command line, i.e., using the geth command line, there are some step-by-step guides at:

You may also want to check out Browser Solidity - see How to call Library Function from a Contract? => [error] The contract code couldn't be stored, please check your gas amount. undefined for an example.

4
  • O my god!! Thank you so much I will try it out once I got the computer. Can I ask you what is the payable modifier in the contract? I have seen a lot of contracts have this function to handle translation. Somebody said if we do not have it, once it throw, all the gas will be consumed. Thank so much. Commented Jan 2, 2017 at 17:30
  • Any function that is marked payable, including the default function (see ethereum.stackexchange.com/a/9297/1268) is able to receive ethers sent with the transaction invoking the function. An error will be thrown if you send ethers when calling a function that is not marked payable. This is so you can design contracts where a user cannot accidentally send ethers when it is not required. Commented Jan 2, 2017 at 22:26
  • 1
    Thank again. Everything is working fine. Should I use uint to be the type of variable to record ehter send? When I send 1 Ether to the contract, it shows 1000000000 wai instead. Finally, I would like to learn the cml to run the contract. Do you have some recommended link for me? Many thanks. Commented Jan 7, 2017 at 4:55
  • See updated answer for response to the questions in your comment above. Commented Jan 9, 2017 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.