0

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

enter image description here

2
  • What exactly do you mean when you say send tokens with coins together? When the first method fails what's the error message? Can you provide a small reproducible example?
    – Ismael
    Sep 5 at 18:15
  • 1
    Thanks answer, I think , this is problem in mobile MetaMask or WalletConnect, Desktop version work correct, It send only Tokens. And mobile version send Token+ETH together 800Tokens+800ETH inone click. I send my problem in their supports too Sep 6 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.