Loading...
pragma solidity ^0.8.5;
contract send_ether {
function send_ether_to_smartcontract() public payable{
}
function getbalance(address add) public view returns(uint256) {
return add.balance;
}
function send_ether_to_address(address payable receiver) public returns(bool) {
return receiver.send(100);
}
}
To send ethers from smart contract first it need to have ethers in smart contract, unless and until we have ethers in smart contract we can't send it to another account
In above smart contract three functions are there which are send_ether_to_smartcontract(), getbalance(address add), send_ether_to_address(address payable receiver)
first function is used to send ethers to smart contract for that function need to be payable to know about how to send ethers to smart contract refer to following link sending ethers to smart contract
second function is used to get balance of that address which is passed as a parameter
thrid function is used for sending ethers to specific address metioned in the parameter to send ethers to that address the address should be payable so we declared address as payable in above code . we can send ethers to address using send() and transfer() function.
but it is better to use send function because if any error occurs during transaction then send() function will return false otherwise in case of successs it returns true but in case of transfer() function error occurs in case of rejection of transaction or failure of transactions.