3

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?

2

Work perfectly on testnet.

I'm using the stripCrLf script at How to load Solidity source file into geth.

Here's your code, slightly tidied, saved into MyEscrow.sol :

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;
    }
}

I ran the following command to flatten your code:

user@Kumquat:~/ESE/Escrow$ echo "var myEscrowSource='`stripCrLf MyEscrow.sol`'"
var myEscrowSource='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; }}'

I executed the following code in my geth --cache=1024 --testnet console command line:

> var myEscrowSource='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; }}'
undefined
> var myEscrowCompiled = web3.eth.compile.solidity(myEscrowSource);
undefined
> personal.unlockAccount(eth.accounts[0], "MyVerySecretPasswordNumber1");
true
> var myEscrowContract = web3.eth.contract(myEscrowCompiled.MyEscrow.info.abiDefinition);
undefined
> var myEscrow = myEscrowContract.new({from:web3.eth.accounts[0], data: myEscrowCompiled.MyEscrow.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);
      }
    }
  }
)
Contract mined! Address: 0x3fd50995536919085c28fdf9e07a03bad955cc33

myEscrow.start(eth.accounts[0], {
  from:web3.eth.accounts[0], 
  data: myEscrowCompiled.MyEscrow.code,
  gas: 1000000
});
"0x0b2ec2ee98b21214cca5be9294f3c019239d3d90f6e23c03a3eb7d6fcc8c1c29"
> myEscrow.queryNumEscrows()
1

Your code is working perfectly on testnet. Check your deployment statement, in particular your myescrow.start.sendTransaction(...) statement.

  • Awesome! Looks like we need to use selfdestruct now though. In place of suicide. – Keith Holliday May 29 '18 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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