[Ethereum] Transfer from contract address

ethereum-wallet-dapppayablesoliditytransactions

I created a contract with a payable function but the ether is stored in the contract I am looking for a way to transfer the ether to another address

Best Answer

If the ether is already in the contract and you do not have the functionality to transfer ether already implemented in it, the ether will be forever in the contract.

A simple contract that receives ether and allows for transferring is shown below. Only the person that deploys the contract will be able to transfer the ether.

pragma solidity ^0.4.24; 

contract myContract{

    address public owner;

    constructor() public {
        owner = msg.sender;
    }

    function transfer(address to, uint256 amount) public {
        require(msg.sender==owner);
        to.transfer(amount);
    }

    function () public payable {}
}

Hope this helps

Related Topic