ethers.js: Error: insufficient funds (version=4.0.47)
Hi All, I am using this library to send usdt with the following code, but when I pass in 50 as amount to be sent to another address and my usdt balance is 97.59, then I got error: insufficient funds, but I have 97.59 usdt in my account, only sending 50, also my ETH balance in my account is 0.00125, which is for the gas fee:
wallet sendTUSDToAddress…error: Error: insufficient funds (version=4.0.47) 2020-05-28T16:38:10.716047+00:00 app[web.1]: at Object.throwError (/app/node_modules/ethers/errors.js:76:17) 2020-05-28T16:38:10.716047+00:00 app[web.1]: at /app/node_modules/ethers/providers/json-rpc-provider.js:276:36 2020-05-28T16:38:10.716048+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5) { 2020-05-28T16:38:10.716049+00:00 app[web.1]: reason: ‘insufficient funds’, 2020-05-28T16:38:10.716050+00:00 app[web.1]: code: ‘INSUFFICIENT_FUNDS’, 2020-05-28T16:38:10.716050+00:00 app[web.1]: transaction: { 2020-05-28T16:38:10.716051+00:00 app[web.1]: nonce: 0, 2020-05-28T16:38:10.716052+00:00 app[web.1]: gasPrice: BigNumber { _hex: ‘0x0826299e00’ }, 2020-05-28T16:38:10.716054+00:00 app[web.1]: gasLimit: BigNumber { _hex: ‘0xa0ed’ }, 2020-05-28T16:38:10.716054+00:00 app[web.1]: to: ‘0xdAC17F958D2ee523a2206206994597C13D831ec7’, 2020-05-28T16:38:10.716054+00:00 app[web.1]: value: BigNumber { _hex: ‘0x00’ }, 2020-05-28T16:38:10.716056+00:00 app[web.1]: data: ‘0xa9059cbb000000000000000000000000df59a6d6c2f09210a60033e513ffd8d61c69be1f0000000000000000000000000000000000000000000000000000000002faf080’,
My code is:
`try{ let usdAbi = Token.abi; let contract = new ethers.Contract(contractAddressUSD, usdAbi,PROVIDER); let wallet2 = new ethers.Wallet(privateKeyDec, PROVIDER); let contractWithSigner = contract.connect(wallet2);
var amount2 = utils.parseUnits(amount.toString(), 6).toNumber();
let usdtBal = await contract.balanceOf(fromAddress);
console.log("wallet sendTUSDToAddress...amount2: ", amount2);
usdtBal = usdtBal.toString();
console.log("wallet sendTUSDToAddress...usdtBal: ", usdtBal);
if(Number(usdtBal) >= amount2){
var transfer = await contractWithSigner.transfer(toAddress, amount2);
console.log("wallet sendTUSDToAddress...transfer: ", transfer);
return transfer;
}else{
return {
error: "Not enough Tether USD in your wallet",
usdtbal: usdtBal
}
}
}catch(error) {
console.log("wallet sendTUSDToAddress...error: ", error);
return {
error: error,
}
}`
Any clues? Thanks for your help.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (5 by maintainers)
@zemse Thank you, turned out to be a problem with the wallet.
@Ranal Can you confirm if you are using the right wallet (basically the one with funds)?
Also few more issues you might run into:
swapETHForExactTokens
you need to pass in avalue
overridegasPrice
override is too less for your transaction to go through on Ropsten. You may pay moreethers.utils.parseUnits('10', 'gwei')
(you can also use EIP1559 for optimum pricing but not necessary until you make this work)Date.now()
is in milliseconds but uniswap expects seconds to be passed, so you should convert to seconds:Math.floor(Date.now()/1000) + 60 * 5
.