ฝาก Ether ไว้ในสัญญา
Sep 30 2020
ฉันได้เพิ่มฟังก์ชันสามอย่างด้านล่างลงในสัญญาที่ทำให้ใช้งานได้ตามที่อธิบายไว้ในบทความ https://programtheblockchain.com/posts/2017/12/15/writing-a-contract-that-handles-ether/
ฉันปรับใช้โดยใช้ Remix บน Rinkeby เมื่อฉันป้อน 1 Ether ในธุรกรรมการฝากใน Remix ฉันได้รับข้อผิดพลาด "Gas Estimation Failed"
เหตุใดฟังก์ชันการฝากจึงเกิดข้อผิดพลาด
ขอขอบคุณ
ฟังก์ชั่นถอน () สาธารณะ {msg.sender.transfer (ที่อยู่ (นี้) .balance); }
function deposit(uint256 amount) payable public {
require(msg.value == amount);
// nothing else to do!
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
อัปเดต
ฉันพยายามใช้ฟังก์ชันทางเลือก แต่รีมิกซ์ไม่ถูกใจ
ความแข็งของ pragma> = 0.4.0 <0.7.0;
ขอขอบคุณ
คำตอบ
1 Picard78 Sep 30 2020 at 15:48
- ฉันใช้ฟังก์ชันทางเลือกด้านล่างและใช้งานได้
receive() external payable {}
- โพสต์นี้คือสิ่งที่ฉันกำลังมองหาในคำถามเดิมของฉัน ทุกอย่างทำงานได้ดีในขณะนี้
คุณส่ง Ether เป็นฟังก์ชันไปยังสัญญาโดยใช้ Remix ได้อย่างไร?