New to Solidity...
I am studying how to deposit Ether into a smart contract by setting a parameter in a function. Based on the value the function receives, the msg.sender is able to send a predetermined amount of Ether.
The idea is that if a value of 1 - 3 is provided, then 24, 12, or 6 Ether is sent from the msg.sender to the contract address. I set z = j to verify that the value was received by the function. Variable t is the value in Wei and is set to msg.value. It appears msg.value is properly set as the value of t gets updated according to the provided input value.
The issue I encounter is that Ether is not transferred when the function is called. Useful guidance would be most appreciated.
I am using Remix and have confirmed that all accounts have been unlocked.
Below is the source...
pragma solidity ^0.4.18;
contract ETHTEST2 {
mapping(address => uint256) public deposits; //depost
uint256 public z;
uint256 public t;
function sendETHtoContract(uint256 j) public payable { //msg.sender & msg.value test - Work in Progress
if (j == 1){
z = j;
msg.value == t;
t = 24000000000000000000 wei;
address(this).transfer(msg.value);
return;
}
if (j == 2){
z = j;
t = 12000000000000000000 wei;
address(this).transfer(msg.value);
return;
}
if (j == 3){
z = j;
t = 6000000000000000000 wei;
address(this).transfer(msg.value);
return;
}
if (j >=4 || j < 0){ //works
revert();
return;
}
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
function() public payable {
// this function enables the contract to receive funds
}
}