Ich versuche, diesen Beispielcode zu testen:
contract MyContract {
function foo(address a) returns (uint) {
// send ether with default 21,000 gas
// likely causes OOG in callee
a.send(1 ether);
// send ether with all remaining gas
// but no success check!
a.call.value(1 ether)();
// RECOMMENDED
// send all remaining gas
// explicitly handle callee throw
if(a.call.value(1 ether)()) throw;
return a.balance;
}
Sehr einfach, senden Sie einfach 1 Ether an eine bestimmte Adresse und senden Sie dann den Adresssaldo zurück. Ich bekomme jedoch immer 0 als Ausgabe, was bedeutet, dass das Senden fehlgeschlagen ist:
Was ist los mit dir?
Was fehlt, ist der zahlbare Modifikator.
Ich habe dieses Stück Code getestet:
contract MyContract {
function foo(address a) payable returns (uint) {
a.call.value(1 ether)();
return a.balance;
}
}
Ich habe es bereitgestellt und dann mit Wert auf 2 ausgeführt (bedeutet 2 Ether) und es funktioniert. Hier ist die Ausgabe:
Die Ausgabe ist 1 ETH in Wei.
Lukas Zuchowski
kuppel etwas