-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFirstCodeInSolidity.sol
More file actions
35 lines (26 loc) · 1.37 KB
/
FirstCodeInSolidity.sol
File metadata and controls
35 lines (26 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pragma solidity ^0.8.17;
// SPDX-License-Identifier: MIT
contract FirstCode{
// Kontrat için sahip ve bakiye değişkenleri tanımlama, Define owner and balance variables for the contract
address public owner;
uint public balance;
// Kontrat sahibini tanımlamak için constructor, Constructor to define the contract owner
constructor(){
owner = msg.sender;
}
// Fonksiyonun çalışması için payable olması gerekli, The function must be payable for it to work.
receive() payable external {
// gelen tutarı bakiyeye aktarma
balance += msg.value;
}
// Fonksiyonun tanımlanması ve gerekli parametrelerin yazılması, Defining the function and writing the necessary parameters
function withdraw(uint amount, address payable destAddr) public {
// require sağlanmaz ise fonksiyon devam etmez ,If require is not supplied, the function does not continue.
require(msg.sender == owner,"Only owner can withdraw");
require(amount <= balance, "Insufficient funds");
// parametre olarak girilen adrese aktarımın yapılması, Transferring to the address entered as a parameter
destAddr.transfer(amount);
// transfere göre bakiyenin güncellenmesi, Updating the balance according to the transfer
balance-=amount;
}
}