Search code examples
ethereumsoliditysmartcontractsweb3js

Smart contract transfer eth to address failed


I'm trying to send eth from smart contract to contract owner's address but in vain. Here's my contract function:

function ownerDebit(uint amount) public payable onlyOwner returns(bool status){
  status = owner.send(amount);
  return status;
}

I'm using NodeJS and Web3JS to interact with this contract:

contract.methods.ownerDebit(10000000000000000).call().then(function(response){
    console.log(response);
});

And the response in console.log was "true".

But the eth in my account remain the same.


Solution

  • address(this) is used to get the address of the contract.

       status = address(this).transfer(owner, amount)