0

I am new with solidity. I've implemented this withdraw function

 function withdraw() public payable onlyOwner {
      require(payable(msg.sender).send(address(this).balance));

}

And I am calling this in the dapp I am creating thats linked to Metamask:

   ...methods
            .send({
                gasLimit: "",
                from: msg.sender,
                to: *contract owner address here*,
                value:...,

}

So the code seems to work as I can transfer tokens and deduct fee from the wallet. However, the "value" is not going to the stated "to" but still in contract. Anyone can help?

bugbytes
  • 101
  • 1
  • Hi so do I use like this: function withdraw() public payable onlyOwner { require(payable(msg.sender).call(address(this).balance));

    } and in Metamask function calls in the "call" instead of "send"?

    – bugbytes Sep 17 '21 at 09:32
  • Why ‚to‘ is contract owner address, itshould be contract address? And why is your withdrawal function payable – Majd TL Sep 17 '21 at 11:07
  • I am trying to try withdraw the money from the contract to owner address as soon as sender sends in but it is not going through... Whats the best way to withdraw money from the contract? – bugbytes Sep 17 '21 at 11:29
  • When ‚to‘ is not your contract Address, then u are not calling the contract and not the method withdraw in it. – Majd TL Sep 17 '21 at 14:29
  • Can u show us the whole Frontend method !? What does …methods mean – Majd TL Sep 17 '21 at 14:30
  • Methods come from here: https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html - contract.methods.somFunc().send({from: ....}) .on('receipt', function(){ ... }); - it sends the token but ether goes to contract. how do I withdraw via this function? I added a "to" but it doesnt work. Do I have to call the withdraw function separately? – bugbytes Sep 17 '21 at 15:35
  • yes you need to call the withdraw function separately. – Majd TL Sep 27 '21 at 09:50

0 Answers0