I'm using Parity ( "ropsten" test net), Nodejs and web3js to deploy smart contract from my system. Parity is synchronised in test mode, but when I run below code using Nodejs, it gave me a transaction id "https://ropsten.etherscan.io/tx/0xa229e52224e7200337aa7893fea71c83e79cd5b2b37234a1559d9e6a7512385d", but when I verified this transaction on etherscan ropsten testnet, then I found that transaction not mined by etherscan. Not sure why transaction not moved from my local "Parity" node to etherscan.

Any help would be appreciated.

var Web3 = require('web3');
let fs = require("fs");
var solc = require('solc');

if( typeof Web3.currentProvider !== 'undefined'){
    web3 = new Web3( Web3.currentProvider );
    web3 = new Web3( new Web3.providers.HttpProvider("http://localhost:8545"));

async function deployContract(){

    var address = await web3.eth.getAccounts()
    var contractAdminAddrs = address[2]
    console.log("Contract deployed from: "+contractAdminAddrs);

    var input = {
        //'IERC20.sol': fs.readFileSync('IERC20.sol', 'utf8'),
        //'SafeMath.sol': fs.readFileSync('SafeMath.sol', 'utf8'),
        'Distribution.sol': fs.readFileSync('Distribution.sol', 'utf8')
    let compiledContract = await solc.compile({sources: input}, 1);

    //return false;

    let abi = compiledContract.contracts['Distribution.sol:Distribution'].interface;
    let bytecode = '0x'+compiledContract.contracts['Distribution.sol:Distribution'].bytecode;

    console.log("Contract Deployment Gas Estimate=")
    var gasEstimate = web3.eth.estimateGas({
        to: contractAdminAddrs,
        data: bytecode

    let Token = new web3.eth.Contract(JSON.parse(abi)); 

    //return false;

    //var gasEstimate = 4500000; //Default gas
    var gas_Estimate = 4500000    //Calculated from above function,used static
    var gasPrice = 30000000000;

    var lms = Token.deploy(
            from: contractAdminAddrs,
            gas: gas_Estimate,
            gasPrice: gasPrice
        function(error, transactionHash){ 
            console.log("send function error=")

        .on('error', function(error){ 
            console.log("contract deploy error=")
        .on('transactionHash', function(transactionHash){ 
            console.log("transactionHash 2nd function=")
        .on('receipt', function(receipt){
            console.log(receipt.contractAddress) // contains the new contract address
        .on('confirmation', function(confirmationNumber, receipt){ 
            console.log("Confirmation Number=")
            console.log("New Contract address=")
            console.log(newContractInstance.options.address) // instance with the new contract address


//Call function to deploy contract

1 Answer 1


You can use the NodeJS script below for testing whether or not your Parity node is synced and ready to receive requests.

Run it as a process next to your Parity process (i.e., on the same machine).

This process is essentially an HTTP server, which communicates with the Parity process on one port, and with your HTTP client (e.g., browser) on another port.


You can generate your ETHERSCAN_KEY as follows:

By the way, this key is good for both Ropsten (test-net) and Homestead (main-net).

For SYNC_THRESHOLD, you can use 10 for now, and figure out later the best value to use. This parameter indicates the permitted difference between the Parity node's current block and the highest block on the chain (which we obtain from etherscan.io). If the difference between these two values is SYNC_THRESHOLD or less, then the Parity node is ready to receive requests, and the server will return 200. Otherwise, the Parity node is not ready to receive requests, and the server will return 500.

let Web3    = require("web3");
let http    = require("http");
let request = require("request");

let SERVER_PORT    = process.argv[2];
let NODE_ADDRESS   = process.argv[3];
let ETHERSCAN_KEY  = process.argv[4];
let SYNC_THRESHOLD = process.argv[5];

let server = http.createServer(async function(externalRequest, externalResponse) {
    request.get("https://api-ropsten.etherscan.io/api?module=proxy&action=eth_blockNumber&apikey=" + ETHERSCAN_KEY, async function (error, response, body) {
        let externalResponseCode;
        let externalResponseBody;
        if (error) {
            externalResponseCode = 500;
            externalResponseBody = "error: " + error;
        else if (!response) {
            externalResponseCode = 500;
            externalResponseBody = "no response";
        else if (response.statusCode != 200) {
            externalResponseCode = 500;
            externalResponseBody = "bad response";
        else {
            let web3 = new Web3(NODE_ADDRESS);
            let currentBlock = await web3.eth.getBlockNumber();
            let highestBlock = parseInt(JSON.parse(body).result);
            if (web3.currentProvider.constructor.name == "WebsocketProvider")
            externalResponseCode = highestBlock - currentBlock > parseInt(SYNC_THRESHOLD) ? 500 : 200;
            externalResponseBody = `currentBlock = ${currentBlock}, highestBlock = ${highestBlock}`;
        console.log(externalResponseCode, externalResponseBody);
        externalResponse.statusCode = externalResponseCode;

server.listen(SERVER_PORT, async function(error) {
    if (error)
        return console.log(error);
    console.log(`server is listening on port ${SERVER_PORT}`);
  • Thanks @goodvibration for your detailed code, let me check if this helps me to resolve parity node issue. Aug 7, 2018 at 6:37
  • I run your code and got "currentBlock = 3788976, highestBlock = 3788976" that means my parity ropsten testnet node is synchronised. Your code is very useful to validate node status, I'm using "Parity-ui" to check parity syn. status. Thanks for your help. Aug 7, 2018 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.