Result when calling smart contract function is different in dApp than on Remix

So basically, when I call my smart contract I get prompted this:


this is what I wans

however, when I run my code in my dApp, which is basically eth_sendTransaction, I get prompted this

Can someone explain me why I get prompted 2 different things when I run the same smart ocntract function?

Code I use in my dAPP

const tokenContract = new web3Client.eth.Contract(tokenABI, wethAddress);

    const amountToSpend = web3Client.utils.toWei("1000", "ether"); // Adjust the amount as needed

    console.log(amountToSpend)
    
      // Now that you have the gas estimate, you can use it in the eth_sendTransaction call

    
      window.ethereum
        .request({
          method: 'eth_sendTransaction',
          params: [{
            from: address,
            to: spendingContractAddress,
            data: tokenContract.methods.approve("0x0DFbFe474270c52D653E43654A7494E5CaA42876", amountToSpend).encodeABI(),
            gas: web3Client.utils.toHex(27042n),
          }],
        })
        .then((txHash) => {
          //console.log(txHash)
        })
        .catch((error) => {
          console.log(error)
        });
        

      }

my smart contract:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Contract is ERC20{
    constructor() ERC20("Backtest_crypto", "BACKTEST"){
         _mint(msg.sender,100000*10**18);
    }
    function approve(address spender, uint256 value) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }
}

Hi @user3620 these are 2 different pieces of code. Please check this pr ``approve tokens` Replace contract with third party within the token allowance flow by filipsekulic · Pull Request #18101 · MetaMask/metamask-extension · GitHub
Are you following any documentation when using ‘eth_sendTransaction’ thanks

Hi thanks for your response. I’m not surre what youre telling me here. I know those are 2 different pieces of code. The function approve() works fine when I call it from Remix, but not when I call it from my dApp, using the code I showed you.
I followed the MetaMask documentation for ‘eth_sendTransaction’

Hi, would you mind opening a ticket we would need more info https://support.metamask.io/hc/en-us/requests/new?ticket_form_id=15901411323931

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.