0

I have a (noob) question on the usage of transfer and send. I have seen that transfer is equivalent to

 require(x.send(k));

When I use send() I know that I have to check whether there was an error during the execution and then handle it like:

   if(!x.send(y)) {
    //...
   }

1) In case there is an error, do I have to write revert() inside the block? To be more specific, since send allows the usage of 2300 gas, in case changes are made inside the receiver contract fallback function, are they reverted automatically?

2) If I use transfer() I don't have to check for errors right? If something goes wrong all code executed is reverted and the remaining gas refunded(I think).

Cheers!

0

In my opinion, only use .send() if you know what you're doing and you want to carry on without reverting your own contract or others in the chain of functions.

If you add a revert() after if(!x.send(y)) { then that will undo whatever else is in that if block and raise an error that will revert everything back to before the transaction was signed ... like a .transfer().

Hope it helps.

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.