The following code will work:
pragma solidity ^0.4.8;
contract A {
function A() payable {
}
function fundTransfer(address b, uint256 amt) {
bool ret = b.send(amt);
}
function getBalance() constant returns (uint256 balance) {
balance = this.balance;
}
}
contract B {
function getBalance() constant returns (uint256 balance) {
balance = this.balance;
}
function () payable {
}
}
The main difference to your original source code is that I have added the fallback ()
function marked with the payable
modifier. Your events work, but I have just replaced your events with constant functions.
Following are the screens that show you how to deploy it using the JavaScript VM with Browser Solidity (or Remix).
The first screen below shows the deployment of contract B
to the address 0xde6a66562c299052b1cfd24abc1dc639d429e1d6
. Note that Value is set to 0.

In the next screen, I have set Value to 100 (ethers) and deployed contract A
. Note that A.getBalance()
returns an error - this is because a value of 100 ethers is sent when invoking A.getBalance()
and this function is not marked with the payable
modifier.

In the next screen, I have set Value to 0 and clicked on getBalance()
and the returned result shows that contract A
has been successfully deployed with 100 ethers.

In the next screen, I will execute A.fundTransfer(...)
with the parameters "0xde6a66562c299052b1cfd24abc1dc639d429e1d6","50000000000000000000"
. Note that the "50000000000000000000"
number will need to be quoted or the number will cause an error.

And the next screen shows the successful transfer of 50 ethers from A
to B
. You can also check that A.getBalance()
returns a value of 50 ethers.

If you remove the function () payable { }
from contract B
, the exercise above will fail.