You have to receive ether in contract while sending ether from web3js. You must have payable function to receive an ether. Lets see example below :
In Web3js :
your_contractInstance.yourReceiverFunction(
your_input_data, // this is optional for sending ether. You can send ether without passing this input variable.
{
from: web3.eth.defaultAccount,
to: your_contract_address,
value: web3.toWei(1, "ether")
});
In solidity :
function yourReceiverFunction(datatypes your_input_data)
payable
public {
//do anything here with your input data
// to receive ether it is not necessary to be any input variable , you just
//need to send ether from web3 and receive here.
//the key point here is to just receive ether and use it
//msg.value holds the ether that sends from web3 in wei.
uint myethervalue = msg.value;
}
Take a refrence of this example. EDIT:
In your case, you are sending ether from one account to another from contract address to externally owned account. Above there is receiving ether from externally owned account to contract account. Lets see how to send ether from CA to EOA.
function send(address receiver)
payable {
uint amount = msg.value;
if (balances[msg.sender] < amount) return;
balances[msg.sender] -= amount;
balances[receiver] += amount;
receiver.transfer(msg.value);
//below Sent() is calling to another function but transfered already to receiver account using `receiver.transfer`
Sent(msg.sender, receiver, amount);
}
This might be helpful !!