Solidity

ERC20 交易未拋出錯誤但餘額未註冊

  • July 30, 2021
//abi not included here, provider is alchemy

const wallet = new ethers.Wallet(PRIVATE_KEY,provider);
tokenB = new ethers.Contract(
USDTaddress,
usdtabi,
   wallet
);
await tokenB.transfer(account2.address,ethers.BigNumber.from(100),{gasLimit: 250000, gasPrice: ethers.utils.parseUnits('100', 'gwei')});

   let balanceUSDT = await tokenB.balanceOf(account2.address);
console.log(`Current account2 USDT balance:${balanceUSDT.toString()}`);
   

此程式碼沒有拋出任何錯誤,但 USDT 餘額顯示為 0。這是在安全帽本地網路上,合約已經實例化。包括總供應在內的其他功能執行良好。謝謝

當您呼叫該transfer函式時,該交易仍等待礦工探勘,因此在此之前,您不會看到餘額增加。要解決此問題,您可以等到交易被探勘。

const tx = await tokenB.transfer(account2.address,ethers.BigNumber.from(100),{gasLimit: 250000, gasPrice: ethers.utils.parseUnits('100', 'gwei')});

await tx.wait(); // wait for tx to be mined

let balanceUSDT = await tokenB.balanceOf(account2.address);

引用自:https://ethereum.stackexchange.com/questions/106259