Last active
August 27, 2017 21:39
-
-
Save Solid-Code/5ffd6041129aba33829db61e70e3a4e9 to your computer and use it in GitHub Desktop.
Sample code to transfer ether with a contract to contract function call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.13; | |
contract ForwardPaymentDemo { | |
//init contract variables | |
address owner; | |
address public RecievePaymentsDemo_addr; | |
function ForwardPaymentDemo() { | |
owner = msg.sender; | |
RecievePaymentsDemo_addr = new RecievePaymentDemo(); | |
} | |
function forward_payment() payable { | |
RecievePaymentDemo(RecievePaymentsDemo_addr).recieve_payment.value(msg.value/2)(); | |
} | |
//change variable functions | |
function changeOwner(address _address) onlyBy(owner) { owner = _address; } | |
modifier onlyBy(address _account) { require(msg.sender == _account); _; } | |
function kill() onlyBy(owner) { suicide(owner); } | |
//Fallback | |
function() payable { msg.sender.transfer(msg.value); } | |
} | |
contract RecievePaymentDemo { | |
//init contract variables | |
address owner; | |
address ForwardPaymentDemo_addr; | |
function RecievePayment() { | |
owner = msg.sender; | |
ForwardPaymentDemo_addr = msg.sender; | |
} | |
event payment_recieved(uint payment); | |
function recieve_payment() payable { | |
payment_recieved(msg.value); | |
} | |
//change variable functions | |
function changeOwner(address _address) onlyBy(owner) { owner = _address; } | |
modifier onlyBy(address _account) { require(msg.sender == _account); _; } | |
function kill() onlyBy(owner) { suicide(owner); } | |
//Fallback | |
function() payable { msg.sender.transfer(msg.value); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment