0

is it possible to send transactions to an address from the smart contract without having to confirm the transaction on metamask? I mean, I need a certain condition to start a transaction that sends coins to a wallet, but I can't make it automatic without my confirmation.

is it possible to do what i ask? Thank you

ps i am using js and web3

1
  • 1
    A contract by itself cannot send a transaction. It is always an external owned account (EOA - not a contract) that initiates a transaction.
    – Ismael
    Oct 27, 2021 at 23:09

1 Answer 1

-1

Yes, it's possible.

First thing: import IERC20 smart contract in your contract

  1. You declare the address: address public toSend;

  2. You approve the address to spend tokens using approve function:

function approve(address spender, uint256 amount) public virtual override returns (bool) {
                _approve(_msgSender(), spender, amount);
                return true;
        
        }

and call it like that:

approve(toSend, amount);
  1. Send the tokens using transfer function

    function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; }

you will call it transfer(toSend, amount)

P.s. If you want ot do that from a web interface please check ether.js documentation

2
  • sorry but i couldn't find a way to make it work via web3
    – Mattia
    Nov 2, 2021 at 11:17
  • The author specifically asked "without my confirmation". Anything you do with browser wallets requires a confirmation. This would only be possible with backend wallets, but your answer doesn't reflect that at all. Dec 21, 2022 at 10:00

Your Answer

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

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