I'll realy appreciate if someone will help me with this problem. I'm currently trying to create an application where users are able to transfer a custom ERC20 token from one metamask wallet to enother via web3 using "eth_sendTransaction" method and window.ethereum, but i'm getting an error above in console of my browser. I suppose the error occures in this part of code:
const transaction = {
'to': contractAddress,
'value': "0x00",
'gasLimit': 6800000,
'gasPrice': 21000,
'nonce': nonce,
'data': data
};
await window.ethereum.request({
method: "eth_sendTransaction",
params: [transaction],
}).then((result) => {console.log(result)}).catch((error) => {console.log(error)});
The rest of my program, where data and nonce are calculated:
import Web3 from 'web3';
const web3 = new Web3(window.ethereum);
await window.ethereum.enable();
const contractABI = require("<file_with_abi>");
const contractAddress = "<address>";
const contract = new web3.eth.Contract(contractABI, contractAddress);
const amount = <amount>;
const from = '<address_from>';
const to = '<address to>';
const data = contract.methods.transfer(to, amount).encodeABI();
const nonce = await web3.eth.getTransactionCount(from, 'latest');
The error is:
`MetaMask - RPC Error: Invalid parameters: must provide an Ethereum address. {code:
-32602, message: 'Invalid parameters: must provide an Ethereum address.'}`