I was doing a USDC transaction on the Ropsten network but in the Metamask documentation I didn't see any place where transactions with tokens were directly touched, I was trying some things I found without success. An example of what I found I took from How to send some custom tokens with MetaMask API?
ethereum.request({
method: "eth_sendTransaction",
params: [
{
from: ethereum.selectedAddress,
to: "0x07865c6E87B9F70255377e024ace6630C1Eaa37F",
data: tokenContract.methods
.transfer("My Wallet", "0.0001")
.encodeABI(),
}
]
});
The problem here is that tokenContract is not defined and I have no idea how to define it
I also found VERY old and really obsolete answers, where mostly web3js is used (And MetaMask doesn't allow to work with web3js anymore as far as I understand, I've already tried it).
In the example above, tokenContract
is address of the token that you want to transfer. Each token contract is deployed on some address, see for example USDT or DAI.
Also, web3js does support MetaMask, see this answer for an example implementation. But MetaMask no longer injects web3js, so that you need to import web3js into the web app separately (previously it was possible to use web3 injected by MM).