0

This is my web3.js function to send the ETH. It works perfectly last month. But today It is not working well. It took more than 1~5 min and then return the fail.

Some times it sent but It also takes very long time to complete the transaction.

This is my current code:

 var web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/GfgWbe8c2O82N18RRSuJ')); // Who holds the token now? var myAddress = address; // This file is just JSON stolen from the contract page on etherscan.io under "Contract ABI" return await web3.eth.getBalance(myAddress); } const sendETHCoin = async (from_addr, to_addr, amount, private_key, fee) => { var content = fs.readFileSync(base_path + 'abiDefinitions/ethAbiContract.json'); content = JSON.parse(content); /////////////////////////////////// // connect to Infura node var web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/GfgWbe8c2O82N18RRSuJ')); // the address that will send the test transaction const addressFrom = from_addr; const privKey = private_key; // the destination address const addressTo = to_addr; var gasPrice = "0x02540BE400"; var gasLimit = "0x250CA"; if(fee == ''){ fee = parseInt(gasPrice, 16) * parseInt(gasLimit, 16); }else{ gasPrice = parseInt(parseInt(fee)/parseInt(gasLimit, 16))+1; if(gasPrice < 1){ gasPrice = 1; } gasPrice = "0x"+gasPrice.toString(16); } //gasPrice = "0x03540BE400"; var txCount = await web3.eth.getTransactionCount(addressFrom); const txData = { nonce: web3.utils.toHex(txCount), gasLimit: web3.utils.toHex(25000), gasPrice: web3.utils.toHex(10e9), // 10 Gwei to: addressTo, from: addressFrom, value: web3.utils.toHex(web3.utils.toWei(amount, 'wei')) } // Signs the given transaction data and sends it. Abstracts some of the details // of buffering and serializing the transaction for web3. const privateKey = new Buffer(privKey, 'hex') const transaction = new Tx(txData) transaction.sign(privateKey) const serializedTx = transaction.serialize().toString('hex') try { return await web3.eth.sendSignedTransaction('0x' + serializedTx) }catch(err) { console.log(err.message); return err.message; } ////////////////////////////// } 

1 Answer 1

1

you can check in etherscan why the transaction fails. if the transaction worked last month, probably the problem is in the gas price. last week the gas prices were too high (safe low was 50 gwei) and I see that you are sending with 10gwei, this is most probably the reason why your transactions fail. Try increasing the gas price and see if it works again

Sign up to request clarification or add additional context in comments.

2 Comments

I have another question. Could you let me know how to get the current acceptable gas price in eth network?
Yes, you can use ethgasstation.info to check the current gas price

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.