1) Send Ether to your contract
Step-1: Create a payable method in your contract just to receive some ether.
Better use empty payable fallback method(Can just use the contract address to send ether)
Ex:
Step-2: Send the transaction to your contract using web3js.
2) Send Ether from one contract to another contract
This can be best illustrated using an example
**Ex:**
//Contract to receive Ether from another Contract
contract TransferEtherTo{
function getBalance() returns(uint){
return address(this).balance;
}
//Empty payable fallback method just to receive some
function() payable{
}
}
//************************************************************///
//Contract to send Ether to another Contract
contract TransferEtherFrom{
//Declaring an instance of TransferEtherTo contract
TransferEtherTo instance;
constructor(){
//Initializing TransferEtherTo contract
instance = new TransferEtherTo();
}
//Returns balance of TransferEtherFrom contract
function getBalance() returns(uint){
return address(this).balance;
}
//Returns balance of TransferEtherTo contract
function getBalanceInstance() returns(uint){
return instance.getBalance();
}
//Transfers ether to other contract
function transfer() payable{
address(instance).send(msg.value);
}
//Fallback function to receive and transfer Ether
function() payable{
address(instance).send(msg.value);
}
}
All the ethers sent to TransferEtherFrom contract(through fallback or transfer() methods) will be sent to TransferEtherTo contract.