I am developing a method to send token using web3. I have parity installed on my local machine (MacOS).

I am new to ethereum & parity. I am getting some errors dont make sense

  1. Can exists another transaction with same nonce? I am using transactionCount. I get this error:

"Returned error: Transaction gas price is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce."

  1. Before sending a transaction I get account balance. When I call balanceOf I get: 2000000000000000000000

Afterwards I get an error: Returned error: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 540000000000 and got: 0.

  1. After sending transaction, I get the transactionHash, some seconds later I get this message "Unhandled rejection Error: Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!" Where do I have to catch this error? why it happens?

Here is my code:

exports.sendTokenTransaction = function(sourceAddress, query, node, abi) {
    return new Promise((resolve, reject) => {

        try {
            var Tx = require('ethereumjs-tx');
            var privateKey = new Buffer(query.priv_key.slice(2), 'hex');

            var provider = new web3.providers.HttpProvider(node.url);
            var w3 = new web3(provider);
            var sender = sourceAddress;
            var receiver = query.dest_address;
            var contractAddress = query.token_address;

            var transactionValue = query.amount;
            var transactionFee = query.gas * query.gasPrice;
            var transactionCost = Number(transactionValue) + Number(transactionFee)

            var tokenContract = new w3.eth.Contract(abi, contractAddress, {from: sourceAddress});

            tokenContract.methods.balanceOf(sourceAddress).call().then(function (balance) {

                commonModel.addLog("ETH", sourceAddress + " balance: " + balance);
                commonModel.addLog("ETH", "Transaction cost: " + transactionCost);

                if (balance < transactionCost) {
                    reject("You don't have enough balance to cover this transaction");
                } else {

                    w3.eth.getTransactionCount(sender).then(function (count) {

                        var transactionObject = {
                            nonce: w3.utils.toHex(count),
                            from: sender,
                            to: receiver,
                            gasLimit: w3.utils.toHex(query.gas),
                            gasPrice: w3.utils.toHex(query.gasPrice),
                            value: w3.utils.toHex(transactionValue),
                            data: tokenContract.methods.transfer(receiver, transactionValue).encodeABI(),
                            chainId: w3.utils.toHex(42) //Kovan

                        var tx = new Tx(transactionObject);

                        var serializedTx = tx.serialize();

                        w3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), function (error, result) {
                            if (!error) {

                                var receipt = w3.eth.getTransactionReceipt(result);

                            } else {
                                var msgError = commonModel.getErrorMessage(error);
                                commonModel.addLog("ETH", msgError);

                    }).catch(function (error) {
                        var msgError = commonModel.getErrorMessage(error);
                        commonModel.addLog("ETHx", msgError);


            }).catch(function (error) {
                var msgError = commonModel.getErrorMessage(error);

        } catch(error) {
            var msgError = commonModel.getErrorMessage(error);


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.