1

I am trying to send an ERC-20 token on Mainnet using web3 v1.x and Infura. I get the error in the title while executing this code.

I have a balance of about 0.14 ETH

var provider = new HDWalletProvider(config.mnemonic, "https://mainnet.infura.io/v3/" + config.infuraKey);

const web3 = new Web3(provider);

const tokenAbi = config.abi;
let tokenContract = new web3.eth.Contract(tokenAbi, contractAddress);


let data = tokenContract.methods.transfer(tAddr, tAmountInWei).encodeABI();
const tx = {
   from: myAddress,
   to: contractAddress,
   gas: web3.utils.toHex(400000),
   gasPrice: web3.utils.toHex(25000000000),
   value: "0x0",
   data: data
};


let eTx = await web3.eth.accounts.signTransaction(tx, tx.from, (err, signedTx) => {
    if (err) {
       console.error(err);
       return err;
    } else {
       console.log('SignedTx: ', signedTx);
       return web3.eth.sendSignedTransaction(signedTx.rawTransaction, (err, res) => {
          if (err) {
             console.error(err);
          } else {
             console.log(res);
             count++;
          }
       });
    }
});

My error below:

Error: insufficient funds for gas * price + value
    at /Users/****/****/node_modules/truffle-hdwallet-provider/dist/index.js:15:632675
    at t.i.onreadystatechange (/Users/****/*****/node_modules/truffle-hdwallet-provider/dist/index.js:15:748948)
    at t.e.dispatchEvent (/Users/*****/*****/node_modules/truffle-hdwallet-provider/dist/index.js:1:142373)
    at t._setReadyState (/Users/*****/*****/node_modules/truffle-hdwallet-provider/dist/index.js:15:753708)
    at t._onHttpResponseEnd (/Users/*****/*****/node_modules/truffle-hdwallet-provider/dist/index.js:15:756793)
    at IncomingMessage.<anonymous> (/Users/*****/*****/node_modules/truffle-hdwallet-provider/dist/index.js:15:756051)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
0

The maximum gas fees that is allocated for your transaction is gas * gasPrice in your case, it's 25 Gwei (giga-wei, or 10^9 wei, or 10^-9 ETH) times 400,000 gas limit,

or 10,000,000 (10^6) Gwei.

10^6 * 10^-9 = 0.001 ETH

so your wallet balance should be sufficient.

I would double-check two things:

Good luck!

0

I found this way to work.

tokenContract.methods.transfer(tAddr, tAmountInWei).send({
         from: myAddress,
         gas: web3.utils.toHex(40000),
         gasPrice: web3.utils.toHex(25000000000),
         value: "0x0"
}).on('transactionHash', (hash) => {
    console.log(`txHash: ${hash}`);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.