【问题标题】:Sending a token via bep20 shows the wrong token on Metamask发送令牌 bep20 web
【发布时间】:2022-01-02 00:41:32
【问题描述】:

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

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

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

请帮忙

【问题讨论】:

    标签: api web3 metamask bep20


    【解决方案1】:

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

    解决方案:在 sn-p 的 params 部分将 to: reciever 替换为 to: contractAddress

    【讨论】:

    • Muito abrigada, ajudou mto.
    猜你喜欢
    • 2022-01-09
    • 2021-11-23
    • 2021-07-14
    • 2021-12-14
    • 2021-08-05
    • 2019-12-31
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多