Here is the method inside the solidity contract

function payUser(address payable _to, uint _amount) public {

        // (bool sent, bytes memory data) = _to.call{value: _amount}("");
        // require(sent, "Failed to send Ether");

The concept of this dapp is that whenever a user wins a game the smart contract should automatically send the won amount of ether.

The problem I'm facing right now is that when I trigger this code using Web3 it will always open the metamask for confirmation. That's not what I want to happen.

const payUserHelper = async () => {
        try {
            const contractAddress = await getContractAddressHelper();
            if (contractAddress) {
                await myContract.methods.payUser('0x9b5e257A1e282768E81A5520B151c8Fb96cD126a', web3.utils.toWei(`${0.0997}`)).send({ from: contractAddress });
        } catch (e) {

NOTE: I just hard coded the receiver for testing purposes, that is an account inside a Ganache. By the way, the smart contract is deployed locally in Ganache. And all accounts for testing is within that Ganache setup.


  • whenever a user wins a game the smart contract should automatically send the won amount of ether WITHOUT opening the metamask for confirmation.


  • If I use the contract address inside the .send({ from: contractAddress }), it would log an error that address is invalid ethereum address

  • If I use the current Metamask selected account (Ganache network) then the Metamask would pop up and ask for confirmation, which is not ideal for this application

I read in the Web3 docs that in order to change something in the smart contract like, it should use the methods' .send() function but the problem here is that it requires a 'from' property. That would always trigger the Metamask to open and confirm.

I really don't know how to implement this one. I appreciate your help. Thank you!


Your Answer

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

Browse other questions tagged or ask your own question.