当它要传输时,它会在元掩码中显示错误的令牌
(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'}]})
}
})()它应该显示令牌,但它显示的不同,

请帮帮忙
发布于 2021-11-23 15:22:45
在传输令牌时,交易需要由合约地址处理(而不是由令牌接收方处理)。请注意,约定接收方是作为transfer()函数的第一个参数传递的。
解决方案:将代码段的params部分中的to: reciever替换为to: contractAddress。
https://stackoverflow.com/questions/70082291
复制相似问题