0

Consider the balance of the address that sends address.transfer(amount); to receive the amount is zero.

For example we have following address with balance of zero:

web3.eth.getBalance('0x123').then(console.log) // 0 

And then this address wants to receive some ether as follows in Solidity code:

address public recipient;  // The account receiving the payments.

function receive(uint256 amount) public {
        require(msg.sender == recipient);

        recipient.transfer(amount);

    }

And at th time of deploying the contract, we initiate recipient to 0x123:

constructor(address _recipient)
        public
        payable
    {
        recipient = _recipient;
    }

Also, we initiate the balance of the contract at the time of deployment.

Then this address tries to call function receive to receive 10 wei as follows (consider the contract address is 0x456) :

var contractInstance = new web3.eth.Contract(abi, '0x456' /*0x456 is contract address*/);

contractInstance.methods.close(10 /*0x123 wants to receive 10 wei*/).send({ from: '0x123' }, function(error, result) {

        console.log(error);

        console.log(result)

    });

when I do this, apparently nothing happens, because when I get the recipient balance, it is still zero.

What is my mistake ?

  • Is the transaction reverted? Is the recipient a smart contract? Does the contract at address 0x456 have enough balance? Are you calling receive from account 0x123? – Henk Jul 16 '18 at 12:20
  • @Henk Thank you. Sometimes I receive this error: "Error: Transaction ran out of gas. Please provide more gas:". Please have a look at this question: HERE : link contract address = 0x456, recipient address = 0x123, when I send 10 wei, balance of contract is 100 wei and function receive is called by 0x123 Thanks – Questioner Jul 16 '18 at 13:03

Your Answer

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

Browse other questions tagged or ask your own question.