A short notice on the two functions
Since version 0.4.13 (actually since this issue is resolved) Solidity has one new important function, the
transfer function. Here is the difference between .send and .transfer:
How send works (or worked)
address.send(amount) it was possible to send an amount to a specific address. There are two problems:
- Only a small amount of gas is sent along (21,000 gas). So the receiver can only emit one single event at max, it can't be another contract that changes state variables or call again other contracts. So it's pretty "safe by accident".
- If an error throw
.sendwill return false and not propagate the error.
.send(...) is now deprecated.
Workaround with call()()
Man developers therefore defaulted back to
recipient.call.value(x)(). Which was merely a workaround and still returns a boolean on success or error. Now exactly this workaround received a name and fully propagates exceptions.
With the new function transfer, it fully propagates errors (on throw)
Also the Solidity by Example Documentation got updated and now uses the
Did I miss something? Do you have opinions? Let me hear in the comments!
Subscribe to Thomas'
Get the latest posts delivered right to your inbox