lgn21st
9/8/2017 - 7:57 AM

ico_submit

ico_submit

const Tx = require('ethereumjs-tx')
const config = require('./rawtx_config')
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"))

var privateKey = new Buffer(config.privateKey, 'hex')

function getNonce(address) {
  return web3.toHex(web3.eth.getTransactionCount(address))
}

function gasPrice() {
  return web3.toHex(config.gasPrice)
}

function gasLimit() {
  return web3.toHex(config.gasLimit)
}

function value(ether) {
  return web3.toHex(web3.toWei(ether, "ether"))
}

var rawTx = {
  nonce: getNonce(config.from),
  gasPrice: gasPrice(),
  gasLimit: gasLimit(),
  to: config.to,
  value: value(config.value),
  data: config.data,
  chainId: 1
}

console.log(rawTx)

var tx = new Tx(rawTx)
tx.sign(privateKey)
var serializedTx = tx.serialize()

console.log("0x" + serializedTx.toString('hex'))
{
    "privateKey": "",
    "from": "",
    "to": "",
    "value": "",
    "gasPrice": "",
    "gasLimit": "",
    "data": "0x"
}
{
  "name": "ico",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ethereumjs-tx": "^1.3.1",
    "web3": "^0.19.0"
  }
}
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"))

var startBlock = 3905264
var sendBlock1 = startBlock - 1
var sendBlock2 = startBlock - 1


var rawTx1 = ""
var rawTx2 = ""

var job1_done = false
var job2_done = false

function fetch() {
  var currentBlockNumber = web3.eth.blockNumber
  console.log("[" + (new Date()).toLocaleTimeString() + "]", "Current block:", currentBlockNumber)

  if (!job1_done && currentBlockNumber >= sendBlock1) {
    web3.eth.sendRawTransaction(rawTx1, function(err, hash) {
      if (err) {
        console.log(err)
      } else {
        console.log(hash)
      }
    })
    console.log("rawTx1 Done!")
    job1_done = true
  }

  if (!job2_done && currentBlockNumber >= sendBlock2) {
    web3.eth.sendRawTransaction(rawTx2, function(err, hash) {
      if (err) {
        console.log(err)
      } else {
        console.log(hash)
      }
    })
    console.log("rawTx2 Done!")
    job2_done = true
  }

  if (!job1_done || !job2_done) {
    setTimeout(fetch, 100)
  }
}

fetch()

setTimeout(function() {}, 3600 * 1000 * 10) // block the process to exit for 10 hours