0

When it goes to transfer, it shows the wrong token in the metamask

(async ()=>{
    const contract = new web3.eth.Contract(ABI, contractAddress);
    const transfer = await contract.methods.transfer(reciever, 1);
    const data = await transfer.encodeABI();
    if(window.ethereum.chainId == '0x61'){
        ethereum
        .request({
        method: 'eth_sendTransaction',
        params: [
            {
                from: ethereum.selectedAddress,
                to: reciever,
                gasPrice: '1000000',
                gas: '',
                data: data, 
        
            },
        ],
        })
        .then((txHash) => console.log(txHash))
        .catch((error) => console.error);
    } else {
        ethereum.request({ method: 'wallet_switchEthereumChain', params:[{chainId: '0x61'}]})
    }
})()

It should show the token, but it shows differently,

enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

When transferring tokens, the transaction needs to be processed by the contract address (not by the token receiver). Note that the contract receiver is passed as the first argument of the transfer() function.

Solution: Replace to: reciever with to: contractAddress in the params section of your snippet.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100