web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.15k stars 4.9k forks source link

Error: Failed to subscribe to new newBlockHeaders to confirm the transaction receipts. #951

Closed masterial closed 6 years ago

masterial commented 7 years ago

This issue happens when invoking methods.myMethod.send types. Happens using the callback and event emitter. Runnin web3-1.0.0.11

frozeman commented 7 years ago

Thank you for trying to help, but issues like this are pretty difficult. if you tell me exactly what you call, and the exact error you get, ideally with some digging yourself will help me fix these issues faster.

masterial commented 7 years ago

Basically, I call a payable function on my contract and the error shows in the browser. Using the callback examples for call and send: http://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12 Let me know what else I should provide.

caustik commented 7 years ago

This sounds like the same problem I'm seeing. Normal method.XXX(...).send works, but when the method is payable the transaction fails to be seen as having been mined. The actual transaction does go through, somehow Web3 just misses it.

Error: Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!

benjaminion commented 7 years ago

Hi,

I'm seeing this as well in a test environment. Let me see if I can add more useful context and make it reproducible for you.

My quick and nasty demo code is here. It sets up a cpp-ethereum instance with a new genesis block and accounts, and then just tries to send a transaction (Eth transfer). I'm also extending the web3.js api using the web3.extend() method to add a couple of test methods provided by cpp-ethereum.

> web3.version
'1.0.0-beta.13'
> ./eth --version
eth version 1.3.0
eth network protocol version: 63
Client database version: 12041
Build: Linux/g++/Interpreter/.

When running against cpp-ethereum in IPC mode, ./eth --test -d /tmp/testeth, everything up to the transfer works, and then I get the error referenced in this issue:

> node set_up_cpp_eth.js 
ACCT0 =  0xE8049892A53Ffe8ca0d0b47C7905Ad81233B4D08
ACCT1 =  0xd4e72e7d8559BDB56b695F1b15be211eDd34a967
1606938044258990275541962092341162602522202993782792835301375
0
Error: Failed to subscribe to new newBlockHeaders to confirm the transaction receipts.
{}
    at Object._fireError (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-utils/src/index.js:56:17)
    at Subscription.checkConfirmation [as callback] (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-method/src/index.js:370:26)
    at /home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-subscriptions/src/subscription.js:289:19
    at Object.<anonymous> (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-requestmanager/src/index.js:82:20)
    at callback (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-providers-ipc/src/index.js:65:40)
    at Array.forEach (native)
    at Socket.<anonymous> (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-providers-ipc/src/index.js:76:51)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at Pipe.onread (net.js:547:20)

When running against cpp-ethereum in RPC mode, ./eth --test --no-ipc -j --admin-via-http, everything up to the transfer works, and then I get an error about "Transaction was not mined within 50 blocks".

> node set_up_cpp_eth.js 
ACCT0 =  0xc01805949847003AB32398EE48e4c9fC2404C511
ACCT1 =  0x551C6CEE6A2677cbfeBB0F15EaBdDab736229e10
1606938044258990275541962092341162602522202993782792835301375
0
Error: Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!
    at /home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-method/src/index.js:362:45
    at tryCatcher (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:497:31)
    at Promise._settlePromise (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:555:18)
    at Promise._settlePromise0 (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:600:10)
    at Promise._settlePromises (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:679:18)
    at Async._drainQueue (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/async.js:125:16)
    at Async._drainQueues (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/async.js:135:10)
    at Immediate.Async.drainQueues (/home/ben/Everything/Ethereum/node_web3/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/async.js:16:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

I've used this web3.js version extensively with testrpc and don't see this issue at all. But I'm finding testrpc to be a bit unstable, so want to give cpp-ethereum a try. I use cpp-ethereum to run the Solidity test suite regularly without any issues.

frozeman commented 7 years ago

We use this before sending th tx:

 if (_.isBoolean(this._method.payable) && !this._method.payable && args.options.value && args.options.value > 0) {
                    return utils._fireError(new Error('Can not send value to non-payable contract method or constructor'), defer.eventEmitter, defer.reject, args.callback);
}

might be that you don't send any values? Will take a look later...

frozeman commented 7 years ago

Can you please re-test with beta.16 (or higher)?

masterial commented 6 years ago

Error still happens on beta.20.

florianlenz commented 6 years ago

Just for reproduceing purpose:

I am getting almost the same error:

Error: Failed to subscribe to new newBlockHeaders to confirm the transaction receipts.
{
  "message": "Method not found",
  "code": -32601
}

When i use the TestRPC everything work's fine. But if i switch to https://ropsten.infura.io/my_token it's showing the error.

okwme commented 6 years ago

infura doesn't allow newBlockHeaders subscription per specs I'm trying to build a custom provider that uses an infura endpoint and don't understand why this doesn't fail when done with metamask? they use infura as well right?

7Ds7 commented 6 years ago

I get the " Failed to subscribe to new newBlockHeaders to confirm the transaction receipts" on a send transaction method on EthereumProvider but it does not happen on MetamaskInpageProvider

frozeman commented 6 years ago

Are you connecting to infura using websockets? Http doesn’t support subscriptions

MaggieNgWu commented 6 years ago

My app try to create a contract, but also failed with error "Error: Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!",

I use private network.

"web3": "^1.0.0-beta.26"

Geth
Version: 1.7.3-stable
Git Commit: 4bb3c89d44e372e6a9ab85a8be0c9345265c763a
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9
Operating System: linux
GOPATH=
GOROOT=/usr/lib/go-1.9```
const DContract = require('./../../contracts/DataContract.json');
function createDataContract(arg){
    return new Promise(function(resolve,reject){
        var newDC = new web3.eth.Contract(DContract.abi);
        newDC.deploy({
            data:DContract.bytecode ,
            arguments: arg
        }).send({
            from: account,
            gas: 4000000,
            gasPrice: 14415708346
        },function(error,transactionHash){
            if(error){
                console.log(error);
                reject(error,"DC","Create Data Contract Failed");
            }else{
                console.log('Ethreum transaction', transactionHash, 'successfully posted.');
            }
        })
        .on('error', function(error){ 
            console.log(error);
            reject(error,"DC","Create Data Contract Failed");
        }).on('transactionHash', function(transactionHash){
            console.log('Ethreum transaction', transactionHash, 'successfully posted.');
        }).on('receipt', function(receipt){
           console.log(receipt.contractAddress) // contains the new contract address
        }).on('confirmation', function(confirmationNumber, receipt){ 
            console.log("receipt: "+JSON.stringify(receipt));
            updateConfirmation(id,confirmationNumber);
        }).then(function(newContractInstance){
            //const SC = new web3.eth.Contract(SContract.abi,config.ethereum.summary);
            console.log("Contract Address : "+newContractInstance.options.address); // instance with the new contract address
            resolve(newContractInstance);
        });
    })
}
downitch commented 6 years ago

Looks like this problem is pretty fresh. I join the community. I am using INFURA to make transactions to deployed contract. I use my own private key to sign the transaction and just send it. Unfortunately it's not working for some reasons and comes up with the same error. Here is the code I use:

let transaction = {
  to: caddress,
  gasPrice: gasPriceHex,
  gasLimit: gasLimitHex,
  data: '0x',
  from: web3.eth.defaultAccount,
  nonce: nonce,
  value: '0x0'
}
let tx = new Tx(transaction);
tx.sign(hexedPrivateKey);
let stx = tx.serialize().toString('hex');
web3.eth.sendSignedTransaction('0x' + stx)
.on('reciept', (rec) => {
  console.log(rec);
});

As @adonley mentioned, and others voted up, here is a quick fix: sed -i '/(timeoutCount - 1 >= TIMEOUTBLOCK)/,+4 d' node_modules/web3-core-method/src/index.js Use it at your own risk, because I've never tested this fix. I am about to use it now and come back to tell about my results.

downitch commented 6 years ago

After poking around, I finally did first transaction like this. I am still unsure, if it is fixed, but I will investigate further to find our how to make it stable, until we get a better solution.

heipacker commented 6 years ago

is this have any result?

fanxiong commented 6 years ago

add pubsub webapi parameter when start up parity or something similar in geth: --web-apis web3,eth,personal,net,traces,rpc,pubsub

barakman commented 6 years ago

@fanxiong:

You mean --ws-apis (not --web-apis).

In any case, --ws-apis=all indeed seems to resolve the problem.

CryptoKiddies commented 6 years ago

@frozeman when you say "Are you connecting to infura using websockets? Http doesn’t support subscriptions", are you referring strictly to third party services that use load balancers? Http subscriptions are working with my personal eth clients.

nivida commented 6 years ago

It does look like a problem of the node configuration and not a problem of web3. Please drop a comment if I should reopen this issue.

klivin commented 5 years ago

Seeing this issue intermittedly on both metamask and portis when calling payable and non payable methods and using send function as in:

contract.mint(0xf8E8054be57ac07cBb3c5168BFfcB54B8328B312,444).send({ from: 0xf8E8054be57ac07cBb3c5168BFfcB54B8328B312 })

Responds immediately with:

Error: Failed to subscribe to new newBlockHeaders to confirm the transaction receipts. {}

I am using Kovan network for testnet. I cannot reproduce on local blockchain. On latest builds for everything as of today.

tomteman commented 5 years ago

@klivin we've added support to promiEvents on Portis, so it should work fine now. Update your SDK to 1.2.14 to see it in action 😃