Beginner in solidity and i'm trying to send ether from an address to a contract. I've tried transferring ether using the Remix compiler test accounts.
pragma solidity 0.4.25;
contract sendether{
function receiveEther() payable public{
}
function sendEther(address _address) payable public{
uint value = 5 ether;
_address.transfer(value);
}
}
I made a simple code to accept ether from an address and send ether to an address.
What i'm not sure is, if i made a Dapp, can i just send ether from my wallet and not execute the receiveEther() function. If no, how can i accept the ether from an address?
sendEther
function doesn't look like it needs to be declaredpayable
, but it does look like it needs some sort of access-restriction, because the way things stand as of now, anyone can call it and get 5 ether out of your contract!address owner
, a functionconstructor() public {owner = msg.sender;}
, and a statementrequire(msg.sender == owner);
at the beginning of thesendEther
function. Thus, only the account used for deploying the contract will be able to invoke this function.