When I use WalletConnect with MetaMask, MetaMask get request, send token and eth together in one transaction, equal amount, example 800tokens+800ETH that is wrong, when I use MetaMask without WalletConnect all ok, sends only 800tokens, that is right. I use different methods but result is only one wrong. Example:
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
// Mikko's test key - don't copy as your mileage may vary
infuraId: "**************"
}
}
};
web3Modal = new Web3Modal({
cacheProvider: false, // optional
providerOptions, // required
disableInjectedProvider: false, // optional. For MetaMask / Brave / Opera.
});
try {
provider = await web3Modal.connect(); //choose WalletConnect and open MetaMask
} catch(e) {
console.log("Could not get a wallet connection", e);
return;
}
let web3 = new Web3(provider);
let mycontract
try {
mycontract=new web3.eth.Contract(contract.abi,contract.address,{
from: selectedAccount // default from address
});
} catch (error) {
}
let amount=parseFloat(800).toFixed(18); //get count tokens
amount=web3.utils.toWei(amount, "ether");
let data=mycontract.methods.transfer(recipient,amount).encodeABI()
// start method 1 to send tokens
let params= [
{
from: selectedAccount,
to:contract.address,
data:data
}
];
provider.request({
method: 'eth_sendTransaction',
params
})
.then((result) => {
// The result varies by RPC method.
// For example, this method will return a transaction hash hexadecimal string on success.
console.log("provider.request:",result)
})
.catch((error) => {
onsole.error("provider.request error:",error)
// If the request fails, the Promise will reject with an error.
});
//end method 1, send 800tokens+800ETH in MetaMask and need only 800tokens
//start method 2 to send tokens
mycontract.methods.transfer(recipient,amount).send({from:selectedAccount},function(err,transfer){
if (err) throw err
});
//end method 2 send example 800tokens+800ETH in MetaMask and need only 800tokens
//Please help me, I don know what do,Where is trouble
When I use WalletConnect with MetaMask, MetaMask get request, send token and eth together in one transaction, equal amount, example 800tokens+800ETH that is wrong, when I use MetaMask without WalletConnect all ok, sends only 800tokens, that is right. I use different methods but result is only one wrong. Example: