0

Is it possible for a smart contract to send out eth in the background?

if so please how would the smart contract look like and the web3 html if possible

1 Answer 1

0

Yes, you can use the transfer function like this;

function SenEth(address payable beneficiary) pubic{
    uint balance = address(this).balance;//This will send all the balance inside the contract
    beneficiary.transfer(balance);
}

You can also send a fixed amount instead of the entire balance. The web3 part would be a simple call to the contract function.

4
  • Thank you but still not clear, cause what i want is send eth from a wallet to another all will run in background. i have tried a few code but still pop up to confirm instead of just send out. can you please explain how to go about this? and also if i already deploy a smart contract on remix and then reload the page do i need to redeploy it? Dec 17, 2021 at 0:19
  • Can you explain the logic of the page using this logic? To understand a little better
    – Julissa DC
    Dec 17, 2021 at 14:07
  • okay, im making a gaming dapp which when you connect your wallet an amount of ether will be remove and send to the contract. and if you win the contract will send it back along side your winnings without having to click confirm again Dec 19, 2021 at 0:55
  • The thing is someone will have to pay for that gas of the returning of the winners price, so it will always ask the user to confirm
    – Julissa DC
    Dec 20, 2021 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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