I'm wanting to pass Ether through some smart contract logic then to some address set in the contract. Is this the possible, or the best way? Or should the ether be passed to contract and the receiver manually collect it?

Something like the code below:

contract Smartcontract{
    address owner;
    mapping (address => uint256) charge;

    function Smartcontracter() public {
        owner = msg.sender;

    function receiverSetPrice (uint256 _value) public{

        charge[msg.sender] = _value;

    function sendether(address _to) public payable{
        require(msg.value >= charge[_to]);
    function checkReceiverAmount(address _to) constant public returns (uint256){
        return charge[_to];

The code is just so you get the rough idea.

I've noticed a problem with it complaining about gas usage.

What would be the best approach to this?


I've noticed a problem with it complaining about gas usage."

It would help if you said exactly what you saw, but I'm going to guess it's a warning from the Solidity compiler that says the gas estimate for sendether is infinite.

If that's the warning, I think it's fine to just ignore it. We typically use the "withdraw" pattern because it's possible for the recipient of the ether to implement a denial of service attack by blocking the transaction, but in this case there's no denial of service attack that matters. (The function does nothing but transfer the ether anyway.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.