Odak modu

Smart Contract Development with Solidity

Send ETH

Code from video: https://solidity-by-example.org/sending-ether/ 

This video explains 3 ways to send ETH in Solidity: transfer, send and call.

A contract receiving Ether must have at least one of the functions below:

  • receive() external payable
  • fallback() external payable

receive() is called if msg.data is empty, otherwise fallback() is called. If neither a receive Ether nor a payable fallback function is present, the contract cannot receive Ether through regular transactions and throws an exception.

  • transfer: There is a gas limit of 2300 gas and it throws an error if there isn’t any receive and fallback functions. It is hardcoded to prevent reentrancy attacks.
  • send: There is a gas limit of 2300 gas and it returns a bool if there isn’t any receive and fallback functions.
  • call: It is the recommended way of transferring ETH, because we can set the amount of gas to be sent. It also returns a bool if there isn’t any receive and fallback functions. However, you should be extra careful when using “call” in a contract since it allows reentrancy attacks. If the sender contract is improperly coded, it can result in draining larger amounts of funds from it than planned. 

Resources:

You can find detailed further information from Solidity Official documentation (in English):

https://docs.soliditylang.org/en/v0.8.14/contracts.html#receive-ether-function 

https://docs.soliditylang.org/en/v0.8.14/contracts.html#fallback-function 

https://medium.com/coinmonks/solidity-transfer-vs-send-vs-call-function-64c92cfc878a

https://coinsbench.com/solidity-how-to-send-ether-transfer-send-call-and-fallback-%EF%B8%8F-c470c836fdf1


Background Pattern
Birlikte öğrenelim

Sektörde en çok aranan yazılım becerilerini kazan

Yapay zeka desteği, birebir mentörlük saatleri, canlı dersler ve senin için özel hazırlanmış içeriklerle eksiklerini tamamla, düzenli geri bildirimler al ve öğrenme sürecini en verimli hale getir.

Yunus Emre Kabakcı

Patika+ mezunu

Patika+ Fullstack Web Development Bootcamp mezunumuz Yunus Emre,

3 ay içinde Katar’dan aldığı teklif ile, global bir şirket olan Pavo Group’da işe başladı!


“İçerik zenginliği, mentor desteği, ileriye dönük bir network sağlaması ve dünyada en çok tercih edilen frameworkler üzerinden bir eğitim veriyor olması Patika+’ı tercih etmemin temel sebepleri oldu!“

Yorumlar

Yorum yapabilmek için derse kayıt olmalısın!