Assessment number 3
Name: AMS. Dheeraj
Regno: 22BCE3897
Send Ether :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract sendEthers {
function sendEther() public payable {
payable(0x19a0870a66B305BE9917c0F14811C970De18E6fC).transfer(1 ether);
function getBalance() public view returns(uint) {
return address(this).balance;
Receive Ether :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract recEthers {
string public calledFunction;
receive() external payable {}
fallback() external payable {}
function getBalance() public view returns(uint) {
return address(this).balance;
}
Using send :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract sendEthers {
function sendEther() public payable {
bool sucess = payable(0x19a0870a66B305BE9917c0F14811C970De18E6fC).send(1 ether);
function getBalance() public view returns(uint) {
return address(this).balance;
Why we should not use send and transfer
Send Ethers
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract sendEthers {
function sendeth() public payable{
bool success = payable(0x19a0870a66B305BE9917c0F14811C970De18E6fC).send(1 ether);
function sendEther() public payable {
payable(0x19a0870a66B305BE9917c0F14811C970De18E6fC).transfer(1 ether);
function getBalance() public view returns(uint) {
return address(this).balance;
}
Receive Ethers
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract recEthers {
string public calledFunction;
receive() external payable {
calledFunction = "receive function called";
fallback() external payable {}
function getBalance() public view returns(uint) {
return address(this).balance;
Using Call function sending ethers
Receive Ethers :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract recEthers {
string public calledFunction;
receive() external payable {
calledFunction = "receive function called";
fallback() external payable {
calledFunction = "Fallback function called";
function getBalance() public view returns(uint) {
return address(this).balance;
}
Send Ethers :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract sendEthers {
function sendeth() public payable{
(bool success,) = payable(0x19a0870a66B305BE9917c0F14811C970De18E6fC).call{value: 1
ether}("using call function");
require(success, "Transfer fail");
function sendEther() public payable {
payable(0x19a0870a66B305BE9917c0F14811C970De18E6fC).transfer(1 ether);
function getBalance() public view returns(uint) {
return address(this).balance;
Type Casting :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract impTyp {
function smalNum() public pure returns(uint256) {
uint8 smallNumber = 255;
uint256 biggerNumber = smallNumber;
return biggerNumber;
contract expCon {
function downcast() public pure returns(uint8) {
uint256 largeNumber = 300;
uint8 smallerNumber = uint8(largeNumber);
return smallerNumber;
}
Event receive Contract :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract Tracker {
event Deposited(address indexed sender, uint amount);
receive() external payable {
require([Link] > 0, "Send some ethers");
emit Deposited([Link], [Link]);
Event send Contract :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract sendEther{
function sendUsingTransfer() public payable{
(bool success,)=payable(0x78FD83768c7492aE537924c9658BE3D29D8ffFc1).call{value: 1 ether}("");
require(success,"Transfer fail");
function getBal() public view returns(uint){
return address(this).balance;
}
Interface - Target code :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract Counter {
uint public count;
function increment() external {
count += 1;
Interface calling code :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
interface ICounter {
function increment() external;
function count() external view returns (uint);
contract UserContract {
function incrementCounter(address _counter) external {
ICounter(_counter).increment();
function getCount(address _counter) external view returns (uint) {
return ICounter(_counter).count();
}
Library :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
library math {
function sqrt(uint y) internal pure returns(uint z) {
if(y > 3) {
z = y;
uint x = y / 2 + 1;
while(x < z) {
z = x;
x = (y / x + x) / 2;
} else if (y != 0) {
z = 1;
contract testMath {
function testSqroot(uint x) public pure returns (uint) {
return [Link](x);
Keccak256 - Hash :-
// SPDX-License-Identifier: MIT
// dheeraj
pragma solidity ^0.8.0;
contract HashFunction {
function hash(string memory _text, uint256 _num, address _addr) public pure returns (bytes32)
return keccak256([Link](_text, _num, _addr));
}
THANK YOU