0

当它去转移时,它在元掩码中显示错误的令牌

(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'}]})
    }
})()

它应该显示令牌,但显示方式不同,

在此处输入图像描述

请帮忙

4

1 回答 1

0

转账代币时,交易需要由合约地址(而非代币接收方)处理。请注意,合约接收者作为函数的第一个参数传递transfer()

解决方案:在您的代码段部分替换to: reciever为。to: contractAddressparams

于 2021-11-23T15:22:44.960 回答