Hi, I am trying to send some ether from a contract to another, like this:
...
function sendSomeMoney(uint n){
secondContract.ping();
if (!secondContractAddr.send(n)) error = true;
else error = false;
}
secondContract is the destination contract, its address is secondContractAddr. Calling ping on secondContract works just fine, while the send returns false.
How do I know which is the problem? Is there a log to know it? For which causes a send may fail?
Thank you
0 ·
Comments
To send ethers to another contract you don't need to send to the contract address:
secondContract.call.value(1 ether);
or if you want to send it via a function call you can do this:
secondContract.ping.value(1 ether);
If you have an argument to the function call then the syntax is:
secondContract.ping.value(1 ether) (arg1);
In the fist case, usign the "call" methode, how could I also invoque the ping function?
This is not working:
sec.call.ping.value(1).gas(4)();
sec.ping.value(1).gas(4);
call
: is it possible to call a methode on a contract usingcall
?I was interested also because with
call
, it does not throw an exception in case of failure, but it just returns a bool (so I have been told...). And I am trying to figure out how exceptions and gas consuption are managed.