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;
}
}