Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Error: Transaction was not mined within750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined! #1763

Closed
ghost opened this issue Jul 9, 2018 · 8 comments

Comments

@ghost
Copy link

ghost commented Jul 9, 2018

I am getting the tx hash returned, but the transaction is never mined. Does anybody know how to solve this issue? Here is the complete error message:

sent 0xb14852674c10adfdaf590c687d5502ea0d992d469791ae8e4094b22ccfc0de5d

(node:20982) UnhandledPromiseRejectionWarning: Error: Transaction was not mined within750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!
at /home/user/code/node_modules/web3-core-method/src/index.js:392:42
at
at process._tickCallback (internal/process/next_tick.js:182:7)
(node:20982) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:20982) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And here is the code I use for nodejs + web3 :

const Web3 = require('web3')
const Tx = require('ethereumjs-tx')

const web3 = new Web3(new Web3.providers.HttpProvider('https://kovan.infura.io/apikey'))
const addressFrom = '0x002D18...'
const privKey = '240462...'
const addressTo = '0x36075430619b21Fff798454e2D5C81E9C18DEe81'

var contractABI = new web3.eth.Contract(
    [...abi...], addressTo);

const contractFunction = contractABI.methods.changeBox(5);
const functionAbi = contractFunction.encodeABI();

function sendSigned(txData, callback) {
    //const privateKey = new Buffer(config.privKey, 'hex')
    const privateKey = Buffer.from(privKey, 'hex');
    const transaction = new Tx(txData)
    transaction.sign(privateKey)
    const serializedTx = transaction.serialize().toString('hex')
    web3.eth.sendSignedTransaction('0x' + serializedTx, callback)
}

web3.eth.getTransactionCount(addressFrom).then(txCount => {
    // construct the transaction data
    const txData = {
        nonce: web3.utils.toHex(txCount),
        gasLimit: web3.utils.toHex(40000),
        //gasPrice: web3.utils.toHex(10e9), // 10 Gwei
        to: addressTo,
        from: addressFrom,
        data: functionAbi
        //value: web3.utils.toHex(web3.utils.toWei(123, 'wei'))
  }

    sendSigned(txData, function(err, result) {
        if (err) return console.log('error', err)
        console.log('sent', result)
    })

})

The smart contract itself looks like this:

pragma solidity ^0.4.24;

contract Test2 {
    address public bank;

    struct Box {
        uint size;
    }
    Box public box;

    constructor() public {
        box.size = 3;
        bank = 0xa2079636c495bDbaCfe0298a5aB92B397c12a3E5;

    }

    function changeBox(uint _change) public {
        box.size = _change;
    }

    function getBox() public returns (uint) {
        return box.size;
    }  
}
@SidhMj
Copy link

SidhMj commented Jul 10, 2018

please use this
https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#signtransaction
to sign the transaction. Also, do not provide nonce it will calculate the latest automatically.
to encode ABI use this
https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-encodeabi
and instead of call back do this

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log)

@ghost
Copy link
Author

ghost commented Jul 14, 2018

Thank you! I am doing it now this way:

const Web3 = require('web3')

// connect to Infura node
const web3 = new Web3(new Web3.providers.HttpProvider('https://kovan.infura.io/api_key'))

// the addresses & private key 
const addressFrom = '0x002D189c25958c60736aE21C966ff3131C2AC849';
const contractAddress = '0x36075430619b21Fff798454e2D5C81E9C18DEe81';
const privKey = '240462d...';

//ABI objects
var contractABI = new web3.eth.Contract(
    [ ...abi... ],
    contractAddress);
const contractFunction = contractABI.methods.changeBox(5);
const functionABI = contractFunction.encodeABI();

// construct the Tx data
const rawTx = {
    //gasPrice: '0x09184e72a000',
    gasLimit: web3.utils.toHex(25000),
    to: contractAddress,
    from: addressFrom,
    data: functionABI
    };

//sign Tx
web3.eth.accounts.signTransaction(rawTx, privKey)
    .then(RLPencodedTx => {
        web3.eth.sendSignedTransaction(RLPencodedTx['rawTransaction'])
            .on('receipt', console.log);
    });

But now I am getting the following error returned:

Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 750000000000000 and got: 0.

The thing is my account has enough funds, you can check it here 0x002D189c25958c60736aE21C966ff3131C2AC849 And if I set gasLimit: web3.utils.toHex(20000),, then I get the error:
Transaction gas is too low. There is not enough gas to cover minimal cost of the transaction (minimal: 21464, got: 20000). Try increasing supplied gas.

Does anybody know why web3 is throwing these wrong errors?

@jroberts101
Copy link

jroberts101 commented Jul 23, 2018

Check your private key. I suspect it should be prefixed by 0x so:
const privKey = '0x240462d...';

@nivida
Copy link
Contributor

nivida commented Aug 10, 2018

Please ask further questions on https://ethereum.stackexchange.com/

@nivida nivida closed this as completed Aug 10, 2018
@Runskey
Copy link

Runskey commented Oct 23, 2018

I got the same issue under Geth/POA private chain.

I referred to this post: #1102, and got the issue resolved by downgrading web3js from 1.0.0-beta.36 to 1.0.0-beta.34.

@pieterhartel
Copy link

Is there way to reduce the 750 seconds? I have about 50,000 transactions in my truffle tests and if many of these take 750 seconds, my tests will take a very, very long time.

$ truffle version
Truffle v5.0.2 (core: 5.0.2)
Solidity v0.5.0 (solc-js)
Node v10.15.0

@ChristobelDiana
Copy link

tried downgrading web3 to 1.0.0-beta.34. still I have the same problem

@parin13
Copy link

parin13 commented Aug 30, 2019

@nivida it doesn't work with infuera, is there any workaround for that

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants