-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllCodeBasicToAdvance.sol
More file actions
2107 lines (1734 loc) · 54.7 KB
/
AllCodeBasicToAdvance.sol
File metadata and controls
2107 lines (1734 loc) · 54.7 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// navvatc tokens
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface INav {
function name()external view returns(string memory);
function symbol()external view returns (string memory);
function transfer(address _to,uint _amount)external returns(bool);
function totalSupply()external view returns(uint);
function balanceOf()external view returns(uint);
}
contract NavCoin is INav{
string private Coinname;
string private CoinSymbol;
uint private CoinTotalSupply;
address private owner;
constructor(string memory _name, string memory _symbol, uint _totalSupply){
Coinname=_name;
CoinSymbol=_symbol;
CoinTotalSupply=_totalSupply;
owner=msg.sender;
balances[owner]+=_totalSupply;
}
mapping (address=>uint)private balances;
function name()external view returns(string memory){
return Coinname;
}
function symbol()external view returns (string memory){
return CoinSymbol;
}
function transfer(address _to,uint _amount)external returns(bool){
uint oldbalance=balances[msg.sender];
require(_amount<=balances[msg.sender], "Insufficient balance");
balances[msg.sender]-=_amount;
balances[_to]+=_amount;
if(oldbalance==balances[msg.sender]){
return false;
}else return true;
}
function totalSupply()external view returns(uint){
return CoinTotalSupply;
}
function balanceOf()external view returns(uint){
return balances[msg.sender];
}
}
// create a tandori nonshop token
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface INav {
function name()external view returns(string memory);
function symbol()external view returns (string memory);
function transfer(address _to,uint _amount)external returns(bool);
function totalSupply()external view returns(uint);
function balanceOf()external view returns(uint);
}
contract NavCoin is INav{
string private Coinname;
string private CoinSymbol;
uint private CoinTotalSupply;
address private owner;
constructor(string memory _name, string memory _symbol, uint _totalSupply){
Coinname=_name;
CoinSymbol=_symbol;
CoinTotalSupply=_totalSupply;
owner=msg.sender;
balances[owner]+=_totalSupply;
}
mapping (address=>uint)private balances;
function name()external view returns(string memory){
return Coinname;
}
function symbol()external view returns (string memory){
return CoinSymbol;
}
function transfer(address _to,uint _amount)external returns(bool){
uint oldbalance=balances[msg.sender];
require(_amount<=balances[msg.sender], "Insufficient balance");
balances[msg.sender]-=_amount;
balances[_to]+=_amount;
if(oldbalance==balances[msg.sender]){
return false;
}else return true;
}
function totalSupply()external view returns(uint){
return CoinTotalSupply;
}
function balanceOf()external view returns(uint){
return balances[msg.sender];
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;
/*
*************************************************************************
Library in solidity
*************************************************************************
*/
// library is used when we implement some extra functionlity to the code
library basicOperation{
function Add(uint a,uint b) public pure returns(uint){
return a+b;
}
function Sub(uint a,uint b) public pure returns(uint){
if(a > b ){
return a - b;
}
else{
return b - a;
}
}
function Divide(uint a,uint b) public pure returns(uint){
return a/b;
}
function Modulas(uint a,uint b) public pure returns(uint){
return a%b;
}
function Multiply(uint a,uint b) public pure returns(uint){
return a*b;
}
}
contract callCulater{
function Addition(uint a, uint b) public pure returns (uint) {
uint sum = basicOperation.Add(a, b);
return sum;
}
function Subtraction(uint a, uint b) public pure returns (uint) {
uint sub = basicOperation.Sub(a, b);
return sub;
}
function Multiply(uint a, uint b) public pure returns (uint) {
uint sum = basicOperation.Multiply(a, b);
return sum;
}
function Divide(uint a, uint b) public pure returns (uint) {
uint sub = basicOperation.Divide(a, b);
return sub;
}
function Modulas(uint a, uint b) public pure returns (uint) {
uint sub = basicOperation.Modulas(a, b);
return sub;
}
}
contract Wallets {
struct PERSONS {
uint256 id;
address payable depositAddress;
string name;
uint256 amount;
}
mapping(address => uint256) public balance;
PERSONS[] public personArray;
PERSONS singlePerson;
function registerUser(
uint256 _id,
string memory _name,
address payable _address
) public payable {
singlePerson = PERSONS(_id, payable(_address), _name, 10 ether);
personArray.push(singlePerson);
byDefaultDeposit(_id);
balance[personArray[_id].depositAddress] = 10 ether;
}
function byDefaultDeposit(uint _id) public{
payable(personArray[_id].depositAddress).transfer(10 ether);
}
function returnSingleUser(address _address)
private
view
returns (PERSONS memory)
{
// return personArray[id];
}
function withdrawAmount(uint _from,uint _to,uint256 _amount) public payable {
uint256 amount = _amount * 1000000000000000000;
// require(balance[personArray[0].depositAddress] >= amount, "Insufficient balance");
payable(personArray[_from].depositAddress).transfer(amount);
balance[personArray[0].depositAddress] -= amount;
personArray[0].amount -= _amount;
personArray[1].amount += _amount;
}
receive() external payable {}
fallback() external payable {}
}
// 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
// 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2
contract Dami_Wallet{
// address public WalletOwner= msg.sender;
mapping(address =>uint) public balanceOf;
event balanceDetails(address receipent,uint amount);
function depositAmount() public payable{
balanceOf[msg.sender] +=msg.value;
emit balanceDetails(msg.sender,msg.value);
}
function getBalance()public view returns (uint){
return balanceOf[msg.sender];
}
function contractBalcne()public view returns(uint){
return address(this).balance;
}
function withdraw(address _addr, uint _amount) public{
require(balanceOf[msg.sender]>=_amount,"low Balance");
balanceOf[msg.sender] -= _amount;
balanceOf[_addr] +=_amount;
// payable(_addr).transfer(_amount);
emit balanceDetails(_addr,_amount);
}
}
contract aliSherWallet{
// accounts (address => balance)
mapping (address => uint) public Accounts;
mapping (address => bool) private DataBase;
////////////////////////////////////////////////////////////////
// fallback() payable external{}
// receive() payable external{}
event Trx(address From,address To,uint Amount);
modifier checkBalance(uint _amount){
require (Accounts[msg.sender] >= _amount,"Poor You");
_;
}
modifier Exist(address _addr) {
require(DataBase[_addr],"Account != Exist");
_;
}
/////////////////////////////////////////////////////////////////
function createAccount() public {
require(!DataBase[msg.sender],"Account Already Exist");
Accounts[msg.sender] = 0 ether;
DataBase[msg.sender] = true;
}
function Deposit() public payable{
Accounts[msg.sender] += msg.value;
emit Trx(msg.sender,msg.sender, msg.value);
}
// Internal Transfer of Assets
function InternalTransfer(address _addr,uint _amount) public checkBalance(_amount) Exist(_addr){
Accounts[msg.sender] -= _amount;
Accounts[_addr] += _amount;
emit Trx(msg.sender,_addr,_amount);
}
// External Transfer of Assets
function Withdraw(address payable _addr,uint _amount) public checkBalance(_amount){
assert(_addr != address(0)); // No gas refund for 0x0000000000000000000000000000000000000000
if(_addr.send(_amount)){
Accounts[msg.sender] -= _amount;
emit Trx(msg.sender,_addr, _amount);
}else revert("Not Sent");
}
}
// multi wallets
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
contract Wallet{
// accounts (address => balance)
mapping (address => uint) public Accounts;
mapping (address => bool) private DataBase;
////////////////////////////////////////////////////////////////
// fallback() payable external{}
// receive() payable external{}
event Trx(address From,address To,uint Amount);
modifier checkBalance(uint _amount){
require (Accounts[msg.sender] >= _amount,"Poor You");
_;
}
modifier Exist(address _addr) {
require(DataBase[_addr],"Account != Exist");
_;
}
/////////////////////////////////////////////////////////////////
function createAccount() public {
require(!DataBase[msg.sender],"Account Already Exist");
Accounts[msg.sender] = 0 ether;
DataBase[msg.sender] = true;
}
function Deposit() public payable{
Accounts[msg.sender] += msg.value;
emit Trx(msg.sender,msg.sender, msg.value);
}
// Internal Transfer of Assets
function InternalTransfer(address _addr,uint _amount) public checkBalance(_amount) Exist(_addr){
Accounts[msg.sender] -= _amount;
Accounts[_addr] += _amount;
emit Trx(msg.sender,_addr,_amount);
}
// External Transfer of Assets
function Withdraw(address payable _addr,uint _amount) public checkBalance(_amount){
assert(_addr != address(0)); // No gas refund for 0x0000000000000000000000000000000000000000
if(_addr.send(_amount)){
Accounts[msg.sender] -= _amount;
emit Trx(msg.sender,_addr, _amount);
}else revert("Not Sent");
}
}
// task to create wallets
contract Wallets {
address owner = msg.sender;
mapping(address => uint256) balance;
function deposit() public payable {
balance[msg.sender] += msg.value;
}
function checkBalance() public view returns (uint256) {
return balance[msg.sender];
}
function withdraw(uint256 _amount) public {
uint256 amount = _amount * 1000000000000000000;
require(
balance[msg.sender] >= amount && owner == msg.sender,
"Insufficient balance"
);
balance[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}
}
// Wednesday 7/6/2023
// mini digitall wallets
contract CreateWallets {
struct Person {
address payable recieveAddress;
string name;
uint256 amount;
}
Person public p1;
function depositAmount() public payable virtual {}
}
contract person1 is CreateWallets {
function setUserDetails(address _depositAddress, string memory _name)
public
{
p1.recieveAddress = payable(_depositAddress);
p1.name = _name;
p1.amount = 0;
}
function depositAmount() public payable override {
p1.recieveAddress.transfer(msg.value);
p1.amount += msg.value;
}
function withdrawAmount(address _address) public payable {
payable(_address).transfer(msg.value);
p1.amount -= msg.value;
}
fallback() external payable {}
receive() external payable {}
}
// Wednesday 7/6/2023
// transfer keyword
contract SenderEither {
address payable reciver;
event info(address recievedAddress, uint256 amount);
constructor(address _address) {
reciver = payable(_address);
}
function transferEthertoAddress() public payable returns (string memory) {
reciver.transfer(msg.value);
emit info(reciver, msg.value);
return "amount sended";
}
}
// in this we used inheratance and super keyword
contract Donation {
event info(string func, uint256 donationAmount);
function sendDonation() public payable virtual {
emit info("DonationContract", msg.value);
}
fallback() external payable {}
receive() external payable {}
}
contract SadkaContract is Donation {
function sendDonation() public payable virtual override {
emit info("sadkaContract", msg.value);
super.sendDonation();
}
}
contract ZakatContract is Donation {
function sendDonation() public payable virtual override {
emit info("zakatContract", msg.value);
super.sendDonation();
}
}
contract charityContract is ZakatContract, SadkaContract {
function sendDonation()
public
payable
override(ZakatContract, SadkaContract)
{
emit info("zakatContract", msg.value);
super.sendDonation();
}
}
//Safe Math Interface
contract SafeMath {
function safeAdd(uint256 a, uint256 b) public pure returns (uint256 c) {
c = a + b;
require(c >= a);
}
function safeSub(uint256 a, uint256 b) public pure returns (uint256 c) {
require(b <= a);
c = a - b;
}
function safeMul(uint256 a, uint256 b) public pure returns (uint256 c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint256 a, uint256 b) public pure returns (uint256 c) {
require(b > 0);
c = a / b;
}
}
//ERC Token Standard #20 Interface
abstract contract ERC20Interface {
function totalSupply() public virtual returns (uint256 _totalSupply);
function balanceOf(address tokenOwner)
public
virtual
returns (uint256 balance);
function allowance(address tokenOwner, address spender)
public
virtual
returns (uint256 remaining);
function transfer(address to, uint256 tokens)
public
virtual
returns (bool success);
function approve(address spender, uint256 tokens)
public
virtual
returns (bool success);
function transferFrom(
address from,
address to,
uint256 tokens
) public virtual returns (bool success);
event Transfer(address indexed from, address indexed to, uint256 tokens);
event Approval(
address indexed tokenOwner,
address indexed spender,
uint256 tokens
);
}
//Contract function to receive approval and execute function in one call
contract ApproveAndCallFallBack {
function receiveApproval(
address from,
uint256 tokens,
address token,
bytes memory data
) public {}
}
//Actual token contract
contract QKCToken is ERC20Interface, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint256 public _totalSupply;
address public YOUR_METAMASK_WALLET_ADDRESS;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
constructor() {
symbol = "hM";
name = "HM coin";
decimals = 2;
_totalSupply = 100000;
balances[YOUR_METAMASK_WALLET_ADDRESS] = _totalSupply;
emit Transfer(address(0), YOUR_METAMASK_WALLET_ADDRESS, _totalSupply);
}
function totalSupply() public view override returns (uint256) {
return _totalSupply - balances[address(0)];
}
function balanceOf(address tokenOwner)
public
view
override
returns (uint256 balance)
{
return balances[tokenOwner];
}
function transfer(address to, uint256 tokens)
public
override
returns (bool success)
{
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
function approve(address spender, uint256 tokens)
public
override
returns (bool success)
{
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transferFrom(
address from,
address to,
uint256 tokens
) public override returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
function allowance(address tokenOwner, address spender)
public
view
override
returns (uint256 remaining)
{
return allowed[tokenOwner][spender];
}
function approveAndCall(
address spender,
uint256 tokens,
bytes memory data
) public payable returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(
msg.sender,
tokens,
address(this),
data
);
return true;
}
fallback() external payable {}
receive() external payable {}
}
// token new project //////////////////////////////////////////////////////////////////////////////////
// pragma solidity 0.8.19;
// //Safe Math Interface
// contract SafeMath {
// function safeAdd(uint a, uint b) public pure returns (uint c) {
// c = a + b;
// require(c >= a);
// }
// function safeSub(uint a, uint b) public pure returns (uint c) {
// require(b <= a);
// c = a - b;
// }
// function safeMul(uint a, uint b) public pure returns (uint c) {
// c = a * b;
// require(a == 0 || c / a == b);
// }
// function safeDiv(uint a, uint b) public pure returns (uint c) {
// require(b > 0);
// c = a / b;
// }
// }
// //ERC Token Standard #20 Interface
// contract ERC20Interface {
// function totalSupply() public returns (uint);
// function balanceOf(address tokenOwner) public returns (uint balance);
// function allowance(address tokenOwner, address spender) public returns (uint remaining);
// function transfer(address to, uint tokens) public returns (bool success);
// function approve(address spender, uint tokens) public returns (bool success);
// function transferFrom(address from, address to, uint tokens) public returns (bool success);
// event Transfer(address indexed from, address indexed to, uint tokens);
// event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
// }
// //Contract function to receive approval and execute function in one call
// contract ApproveAndCallFallBack {
// function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
// }
// //Actual token contract
// contract QKCToken is ERC20Interface, SafeMath {
// string public symbol;
// string public name;
// uint8 public decimals;
// uint public _totalSupply;
// address public YOUR_METAMASK_WALLET_ADDRESS;
// mapping(address => uint) balances;
// mapping(address => mapping(address => uint)) allowed;
// constructor() public {
// symbol = "hM";
// name = "HM coin";
// decimals = 2;
// _totalSupply = 100000;
// balances[YOUR_METAMASK_WALLET_ADDRESS] = _totalSupply;
// emit Transfer(address(0), YOUR_METAMASK_WALLET_ADDRESS, _totalSupply);
// }
// function totalSupply() public returns (uint) {
// return _totalSupply - balances[address(0)];
// }
// function balanceOf(address tokenOwner) public returns (uint balance) {
// return balances[tokenOwner];
// }
// function transfer(address to, uint tokens) public returns (bool success) {
// balances[msg.sender] = safeSub(balances[msg.sender], tokens);
// balances[to] = safeAdd(balances[to], tokens);
// emit Transfer(msg.sender, to, tokens);
// return true;
// }
// function approve(address spender, uint tokens) public returns (bool success) {
// allowed[msg.sender][spender] = tokens;
// emit Approval(msg.sender, spender, tokens);
// return true;
// }
// function transferFrom(address from, address to, uint tokens) public returns (bool success) {
// balances[from] = safeSub(balances[from], tokens);
// allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
// balances[to] = safeAdd(balances[to], tokens);
// emit Transfer(from, to, tokens);
// return true;
// }
// function allowance(address tokenOwner, address spender) public returns (uint remaining) {
// return allowed[tokenOwner][spender];
// }
// function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
// allowed[msg.sender][spender] = tokens;
// emit Approval(msg.sender, spender, tokens);
// ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
// return true;
// }
// // function () public payable {
// // revert();
// // }
// }
// Wednesday 7/5/2023
// all about inheratance
contract Vichle {
event Info(string contractName, string message);
function startEngine() public virtual {
emit Info("vichle", "vicheles engine is started");
}
function stopEngine() public virtual {
emit Info("vichle", "vicheles engine is stopped");
}
}
contract Car is Vichle {
function startEngine() public virtual override {
emit Info("Car", "vicheles engine is started");
}
function stopEngine() public virtual override {
emit Info("Car", "vicheles engine is stopped");
}
}
contract Truck is Vichle {
function startEngine() public virtual override {
emit Info("vichle", "vicheles engine is started");
}
function stopEngine() public virtual override {
emit Info("Car", "vicheles engine is stopped");
}
}
contract SUV is Car, Truck {
function startEngine() public override(Car, Truck) {
emit Info("SUV", "vicheles engine is started");
super.startEngine();
}
function stopEngine() public override(Car, Truck) {
emit Info("SUV", "vicheles engine is stopped");
super.stopEngine();
}
}
// how to override the state variables in a child contract
// ===> we used contracter
contract A {
string name = "contract A";
function getName() public view virtual returns (string memory _name) {
_name = name;
}
}
contract B is A {
// we used constructer to override the states
constructor() {
name = "Contract B";
}
function getName() public view override returns (string memory _name) {
_name = string(abi.encodePacked(super.getName(), "child B"));
}
}
contract Donation {
event info(string func, uint256 donationAmount);
function sendDonation() public payable virtual {
emit info("DonationContract", msg.value);
}
fallback() external payable {}
receive() external payable {}
}
contract SadkaContract is Donation {
function sendDonation() public payable override {
emit info("sadkaContract", msg.value);
}
}
contract ZakatContract is Donation {
function sendDonation() public payable override {
emit info("zakatContract", msg.value);
}
}
// Wednesday 7/5/2023
// all about inheratance
contract Vichle {
event Info(string contractName, string message);
function startEngine() public virtual {
emit Info("vichle", "vicheles engine is started");
}
function stopEngine() public virtual {
emit Info("vichle", "vicheles engine is stopped");
}
}
contract Car is Vichle {
function startEngine() public virtual override {
emit Info("Car", "vicheles engine is started");
}
function stopEngine() public virtual override {
emit Info("Car", "vicheles engine is stopped");
}
}
contract Truck is Vichle {
function startEngine() public virtual override {
emit Info("vichle", "vicheles engine is started");
}
function stopEngine() public virtual override {
emit Info("Car", "vicheles engine is stopped");
}
}
contract SUV is Car, Truck {
function startEngine() public override(Car, Truck) {
emit Info("SUV", "vicheles engine is started");
super.startEngine();
}
function stopEngine() public override(Car, Truck) {
emit Info("SUV", "vicheles engine is stopped");
super.stopEngine();
}
}
// how to override the state variables in a child contract
// ===> we used contracter
contract A {
string name = "contract A";
function getName() public view virtual returns (string memory _name) {
_name = name;
}
}
contract B is A {
// we used constructer to override the states
constructor() {
name = "Contract B";
}
function getName() public view override returns (string memory _name) {
_name = string(abi.encodePacked(super.getName(), "child B"));
}
}
// Tuesday 7/4/2023
// all about inheratance
contract Donation2 {
event info(string func, uint256 donationAmount, bytes data);
function Zakat() external payable virtual {
emit info("zakat", msg.value, msg.data);
}
function Sadka() public payable virtual {
emit info("sadka", msg.value, msg.data);
}
// function userDonate(uint256 _number) public {
// if (_number == 0) {
// Sadka();
// }
// if (_number == 1) {
// Zakat();
// }
// }
fallback() external payable {}
receive() external payable {}
}
contract ZakatContract is Donation2{
function Zakat() public payable override {
emit info("zakatContract is called", msg.value, msg.data);
}
}
contract SadkaContract is Donation2{
function Sadka() public payable override {
emit info("sadkaContract is called", msg.value, msg.data);
}
}
contract Parent {
string name;
uint256 age;
constructor(uint _age,string memory _name){
age = _age;
name = _name;
}
function checkNameAndAge() public virtual returns(uint,string memory) {
return (age,name);
}
}
contract Child1 is Parent(56,'ahmad') {
}
// in this we can accept arrays as input and output in functuion