Newbie: Contract keeps returning empty string

EamorrEamorr Member Posts: 19
edited August 2015 in Solidity
Hello, I'm just getting to grips with smart contracts...

I'm modifying the Greeter contract on ethereum.org

https://ethereum.org/greeter

Here is my Solidity code:
contract mortal {
  address player;

  //this function is executed at initialization and sets the owner of the contract
  function mortal() {
    player = msg.sender;
  }

  //Function to recover the funds on the contract
  function kill() {
    if (msg.sender == player){
      suicide(player);
    }
  }
}


contract Earth is mortal{
  uint amount;
  uint[] selection;

  //this runs when the contract is executed
  function Earth(uint[] _selection, uint _amount) public {
    amount = _amount;
    selection = _selection;
  }

  function info() constant returns (uint) {
    //selection[n] = amount;

    return amount;
  }
}
It compiles fine. I submit it to the network and gets mined OK.

Here is the submission code:


var source = 'contract mortal {  address player;    function mortal() {  player = msg.sender;  }    function kill() {  if (msg.sender == player){  suicide(player);  }  } }   contract Earth is mortal{  uint constant n = 6;   uint amount;  uint[] selection;    function Earth(uint[] _selection, uint _amount) public {  amount = _amount;  selection = _selection;  }   function info() constant returns (uint) {    return amount;  } } ';
var compiled = web3.eth.compile.solidity(source);

var _selection = [1,2,3,4,5,6];
var _amount = 0.01;

var earthContract = web3.eth.contract(compiled.Earth.info.abiDefinition);


var earth = earthContract.new(_selection,_amount,{from:web3.eth.accounts[1], data: compiled.Earth.code, gas: 1000000}, function(e, contract){
    if(!e) {
      if(!contract.address) {
        console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
      } else {
        console.log("Contract mined! Address: " + contract.address);
        console.log(contract);
      }
    }
});


When I run earth.info(), I would like to see 0.01 being returned. Instead, all I see is '0'!!!

What is going on?

Comments

  • EamorrEamorr Member Posts: 19
    edited August 2015
    So the problem here is that:

    var _amount = 0.01;

    There are no floating types in Solidity!

    This works:
    
    var _amount = 0.01;
    _amount = web3.toWei(_amount, 'ether');
    
Sign In or Register to comment.