I tried to build a basic contract from some resources but failed to deposit the ether into this contract. Following is my code, is it correct that "msg.value" and "address(this).balance" be 0 at any time? If so, how can I send ether to another address? If not so, how to deposit money in a correct method?
// can get balance
function getOnesBalance(address addr) public view returns (uint){
return addr.balance;
}
// can get balance
function getMyBalance() public view returns (uint){
return msg.sender.balance;
}
// 0
function getMyBalance2() public view returns (uint){
return msg.value;
}
// 0
function getMyBalance3() public view returns (uint){
return address(this).balance;
}
function deposit(uint _money) public payable {}
function getContractAddr() public view returns (address){
return msg.sender;
}
function() payable {}
deposit
or the fallback function. Are you doing that via code? If so, can you share that code? If not, can you tell us how you're transferring the ether?getContractAddr()
is wrong, it will return the address of the one who called the function..