0

I'm trying to send a transaction for a token with a locked contract. I'm doing this to find out when this contract will be open. So I'm expecting to get some kind of error like "ERC-20 Token Transfer Error (Unable to locate corresponding Transfer Event Logs), Check with Sender" or something, but I get this instead:

Error: insufficient funds for gas * price + value

I saw a lot of articles about this and tried everything, but everything leads to the same error. Is it even possible to make an app check whenever contract will be open? My code:

const main = async () => {
  console.log(`web3 version: ${web3.version}`);

  const myAddress = '0x...';
  const destAddress = '0x...';
  const transferAmount = 1;

  const count = await web3.eth.getTransactionCount(myAddress);
  console.log(`num transactions so far: ${count}`);

  const abiArray = JSON.parse(fs.readFileSync(path.resolve(__dirname, './contract.json'), 'utf-8'));

  const contractAddress = '0x...';
  const contract = new web3.eth.Contract(abiArray, contractAddress, { from: myAddress });

  const balance = await contract.methods.balanceOf(myAddress).call();
  console.log(`Balance before send: ${balance}`);

  const rawTransaction = {
    'from': myAddress,
    'nonce': '0x' + count.toString(16),
    'gasPrice': '0x09184e72a000',
    'gasLimit': '0x2710',
    'to': contractAddress,
    'value': '0x0',
    'data': contract.methods.transfer(destAddress, transferAmount).encodeABI(),
    'chainId': 0x01
  };

  try {
    const privKey = new Buffer.from(WALLET_PRIVATE_KEY, 'hex');
    const tx = new Tx.Transaction(rawTransaction);
    tx.sign(privKey);
    const serializedTx = tx.serialize();

    console.log(`Attempting to send signed tx:  ${serializedTx.toString('hex')}`);
    const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
    console.log(`Receipt info:  ${JSON.stringify(receipt, null, '\t')}`);
  }
  catch (e) {
    console.error('Failed to send transaction');
    console.log(e.message);
  }
};

my wallet private key is in this format (example): 7effd90c52ebcf6ff916a26e3053300ac10d4fecbcd0e46ae2ae861b120d8587

P.S. I use ethereumjs-tx to make traction.

5
  • Your gas limit is too low 10k gas while minimum for a transfer is 21k gas. Try with 125k for a token transfer. And your gas price is too high 10,000 gwei (15gwei is suggested as fast in EthGasStation). I'd suggest to use toWei and numberToHex to make your code more readable. Also run your test in some of the testnet to make sure everything is OK, rinkeby for example.
    – Ismael
    Dec 10, 2019 at 13:34
  • ok so if I want to set 0.000000015 as a gas price, how should I calculate it? Dec 10, 2019 at 13:54
  • To convert from 15 gwei to wei do something like web3.utils.toWei("15", "gwei") or you if you want to use a number instead of a string you can combine with toBN, web3.utils.toWei(web3.utils.toBN(15), "gwei").
    – Ismael
    Dec 10, 2019 at 14:19
  • setting limits to these would still return the same error 'gasPrice': '0x37E11D600', 'gasLimit': '0x2DC6C0', Dec 10, 2019 at 15:04
  • Are you sure private key generates your address? Is chainId correct? Using ethereumjs-util you can generate address from private key ethereum.stackexchange.com/questions/15823/…
    – Ismael
    Dec 10, 2019 at 16:11

1 Answer 1

0

Your error indicates that the ether balance of myAddress is smaller than 0x2710 * 0x09184e72a000.

7
  • good point! but the balance is kinda big there, what data there should be instead for gas price and limit? how to calculate it? Dec 10, 2019 at 12:34
  • @ArnasPecelis: I have checked the balance of your account (0xa288599936125Df4932Cf0B433c60D86cC74dafC) on both mainnet and ropsten. It is zero on both. What network are you on? Dec 10, 2019 at 12:37
  • I don't know how did you got this but that's not my account. I'm on mainnet and have two tokens in my account - ETH and one secret. Dec 10, 2019 at 12:40
  • Insufficient Balance refers to Ether, not to any token that you may or may not have in your account. The account that I have checked matches with the private key that you have posted. Dec 10, 2019 at 12:45
  • I can see on etherscan these: EtherValue: $4.42 (@ $147.43/ETH). So I'm sure that I have ETH to send transactions. That was an example of the key I do use. So I'm pretty sure thats a problem with gas limit and gas price Dec 10, 2019 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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