When calling a state mutating function on the chain, the TX receipt object is returned. In Solidity Browser, under the Javascript VM, a return value is returned if one is set.
Why does the Javascript VM behave in this confusing way?
For example, the following contract contains a state mutation function which returns a value.
contract foo {
uint public bar;
function set(uint newbar) public returns (bool)
{
bar = newbar;
return true;
}
}
In the Javascript VM, the value is shown as returned...
This is contrary to the behaviour of an on chain contract which returns the TX recipt. IOW returns have no purpose in a state mutating function (or am I missing something really fundamental?)
The Javascript VM's return behaviour can lead to a false sense of functionality by which an author (like me, who should have known better) then writes contracts depending upon such return values but which have absoutly no functionality on chain...
Another example that works in VM but breaks on chain is when trying to interact with a 'new' contract...
contract foo {
uint public number = 42;
function set(uint num)
{
number = num;
}
}
contract fooFactory {
foo public kungFoo;
function newFoo()
{
kungFoo = new foo();
kungFoo.set(1); // This call will throw on chain yet works in VM
}
}