Skip to content

Instantly share code, notes, and snippets.

@Solid-Code
Last active August 27, 2017 21:39
Show Gist options
  • Save Solid-Code/5ffd6041129aba33829db61e70e3a4e9 to your computer and use it in GitHub Desktop.
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
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