测试网上总是出现错误:750秒内未进行交易

时间:2018-10-02 13:56:31

标签: node.js web3

/** executes contract method by creating transaction
 * @param {string} from - payer address
 * @param {string} to - payee address
 * @param {int} amount - number of tokens
 * @param {string} type - transaction type
 */
web3.eth.getGasPrice().then(gasPrice => {
    gasPrice *= 2;
    gasPrice = Math.floor(gasPrice);

    var data = myContract.methods.transfer(receiverAddress).encodeABI();
    var nonceValue = 0;
    web3.eth.getTransactionCount(hostAddress).then(function(res){
        nonceValue = res;
        console.log('nonce' , 'nonce = ' + nonceValue);
    })

    var rawTx = {
        nonce: '0x20',
        gasLimit: web3.utils.toHex(99000),
        gasPrice: web3.utils.toHex(gasPrice),
        value: '0x00',
        from:hostAddress,
        to:contractAddress,
        data: data,
        chainId: 3
    }

    var tx = new Tx(rawTx);
    tx.sign(hexPrivateKey);

    var serializedTx = tx.serialize();
    console.log("start sendSignedTransaction");
    console.log("serializedTx", serializedTx.toString('hex'));

    var transaction = web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
    transaction.on('confirmation', (confirmationNumber, receipt) => {
        console.log('confirmation', confirmationNumber);
        res.render('index', { title:"confirmation" + confirmationNumber});
    });
    transaction.on('transactionHash', hash => {
        console.log('transaction hash', hash);
        res.render('index', { title:"transaction hash" + hash});
    });
    transaction.on('receipt', receipt => {
        console.log('transaction reciept', receipt);
        res.json({ receipt });
        res.render('index', { title:"transaction reciept "+receipt });
    });
    transaction.on('error', error => {
        console.log('transaction error', error);
        res.render('index', { title:console.error });
    });
});

即使我提高了汽油价格,并将测试网切换到ropsten / rinkeby ,错误响应也始终需要mo来确认交易已正确发送。有人可以帮我,我哪里错了?

交易错误错误:750秒内未进行交易,请确保交易已正确发送。请注意,它仍可能被开采!

0 个答案:

没有答案