The following smart contract behaves differently on Solidity Browser and testnet:
pragma solidity 0.4.2;
contract mortal {
address owner;
function mortal() { owner = msg.sender; }
function kill() { if (msg.sender == owner) suicide(owner); }
}
contract myEscrow is mortal {
uint numEscrows;
function queryNumEscrows() constant returns (uint) {
return numEscrows;
}
function start() returns (uint) {
numEscrows++;
return numEscrows;
}
}
On Solidity Browser it behaves as it should, increasing the value numEscrows
when start()
is called, and queryNumEscrows()
returns this value correctly.
On testnet, the value numEscrows
seems to be stuck on 0. queryNumEscrows()
always returns 0, no matter how many times start()
has been called.
On testnet I deployed in this way:
personal.unlockAccount("0x47978a69f410d0f61850c92acdb0d4c464d70937", "pass", 86400);
personal.unlockAccount("0x3b877e80b5c0b29d88f3768ed4292b35fdd93a9d", "pass", 86400);
web3.fromWei(eth.getBalance("0x47978a69f410d0f61850c92acdb0d4c464d70937").toNumber(), "ether")
"1673.35...."
var myescrowContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"queryNumEscrows","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"start","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"}]);
var myescrow = myescrowContract.new(
{
from: web3.eth.accounts[0],
data: '60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b6101828061003f6000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480630127efc51461005257806341c0e1b51461007a578063be9a65551461008e5761004d565b610002565b346100025761006460048050506100b6565b6040518082815260200191505060405180910390f35b346100025761008c60048050506100c8565b005b34610002576100a0600480505061015c565b6040518082815260200191505060405180910390f35b600060016000505490506100c5565b90565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561015957600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b60006001600081815054809291906001019190505550600160005054905061017f565b9056',
gas: 4700000
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
Contract mined! address: 0x95162fb5af8fae1970a90d891ca3862b020dda60 transactionHash: 0xfd5107184eba5cd2032759987ed7dace2de3328c2e8461b50b1d5a9a9e3ae12f
https://testnet.etherscan.io/address/0x95162fb5af8fae1970a90d891ca3862b020dda60
// This should be zero, right
myescrow.queryNumEscrows();
0
// Start escrow from Alice to Bob for 1 euro <=> 10^9 weis
myescrow.start.sendTransaction("0x90e8682b63d7922a3e942d4bbd4c88095634a17b", "0x47978a69f410d0f61850c92acdb0d4c464d70937", {from:"0x3b877e80b5c0b29d88f3768ed4292b35fdd93a9d", value:"0x3b9aca00"}, function (err, result) { if (err) { console.error(err); return; } else {console.log('txhash: ' + result)} });
0x445b6c9a7c735a54fd246596d40e2e8726244a91b98c512ca7ff9c1a5bd82c00
// After several minutes ...
myescrow.queryNumEscrows();
0
Why numEscrows
is not increasing?
P.S.: By the way, I have deployed this very smart contract on testnet using Mist and it works, increasing numEscrows
properly. But when deploying directly through geth console, it doesn't work. Why?