I'm working on Solidity Contract, but I cannot find a way to deposit a predefined value from an External Address to the Contract. This is the test code I'm using:
pragma solidity 0.5.12;
contract Payment {
mapping(address => uint256) public balances;
address payable wallet;
constructor(address payable _wallet) public {
wallet = _wallet;
}
function buyToken() public payable {
balances[msg.sender] += 1;
wallet.transfer(0.1 ether);
}
function () payable external{}
function getContractBalance() public view returns(uint) {
return address(this).balance;
}
}
In Remix, if I use msg.value it works fine. I deploy the contract with an Address "1", then I use an Address "2", then I execute buyToken(), so 1 Ether (from Remix Test form) was sent from Address "2" to Address "1". If I use a fixed value (like 0.1 ether) it not works.
What I want is a people can deposit a fixed amount of ETH (in really it will be TRON, but the code is the same) in the contract.
Thanks for help.