1

Getting this error when calling a write function in the smart contract. Please find the code below.

getListedAsValidator: function(address,sender, callback) {
    var self = this;
    var config = require('../config/config');
    var Web3 = require('web3');
    var web3 = new Web3(config.clientEndPoint);
    var sender = config.address;
    var contractAddr = config.contractAddress;


var tokenInstance = new web3.eth.Contract(zecash_artifact.abi, contractAddr, {
  from: sender
});

var txnNonce;
var txnObject;

web3.eth.getTransactionCount(sender)
  .then(function(data){
   // txnnonce = txnnonce + 1;
    txnNonce = data;
    console.log(txnNonce);
    txnObject = {
      from : sender,
      to : contractAddr,
      value : "0x0",
      gasPrice: web3.utils.toHex(web3.utils.toWei('30', 'Gwei')),
      gas: web3.utils.toHex('3000000'),
      nonce: txnNonce,
      data: tokenInstance.methods.setValidators(address).encodeABI()
    };
    console.log(txnObject);

    var Tx = require('ethereumjs-tx');
    var privateKey = new Buffer(config.privkey, 'hex');

    var tx = new Tx(txnObject);
    tx.sign(privateKey);

    var serializedTx = tx.serialize();
    console.log(serializedTx);

    web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
    .on('receipt', function(receipt){
        console.log("Receipt Called");
        callback(receipt.valueOf());

      })
      .on('error', function(err){
        console.log("Error Called: "+ err);

        var minedPending = "Be aware that it might still be mined";
        var sourceErr = " " + err + " ";
        if(sourceErr.indexOf(minedPending) !== -1)
        {
          var rtnObj = {
            "status" : "pending",
            "data" : err,
            "errmsg" : "Your transaction is on the Blockchain. Depending on data traffic, it may take anywhere between 5-30 minutes to execute. Kindly check your wallet again in some time to be sure that the transaction was successfully executed."
            };

          callback(rtnObj.valueOf());  
        }
        else
        {

          callback("ERROR 404");

        }
      });
 });

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.