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
  • 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 at 23:09
0

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

1
  • sorry but i couldn't find a way to make it work via web3
    – Mattia
    Nov 2 at 11:17

Your Answer

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

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