diff --git a/index.js b/index.js index e148c31..6d1ee55 100644 --- a/index.js +++ b/index.js @@ -14,30 +14,28 @@ var express = require('express') , cors = require('cors') , app = express(); -var nonce = parseInt(process.env.NONCE || '1000') - app.use(cors()); app.get('/address/:address', function(req, res, next){ - nonce += 1; - eth.sendTransaction({ - from: address, - to: req.params.address, - gas: 100000, - value: (parseFloat(process.env.AMOUNT) || 1.5) * 1e18, - data: '0xde5f72fd', // sha3('faucet()') - nonce, - }, (err, txID) => { - if (err) { - nonce -= 1; - console.log('Request failed', err) - return res.status(500).json(err) - } - else { - console.log('Successful request:', txID) - res.json({ txID }) - } - }); + eth.getTransactionCount(address, (err, nonce) => { + eth.sendTransaction({ + from: address, + to: req.params.address, + gas: 100000, + value: (parseFloat(process.env.AMOUNT) || 1.5) * 1e18, + data: '0xde5f72fd', // sha3('faucet()') + nonce, + }, (err, txID) => { + if (err) { + console.log('Request failed', err) + return res.status(500).json(err) + } + else { + console.log('Successful request:', txID) + res.json({ txID }) + } + }); + }) }); const port = process.env.PORT || 8181 diff --git a/package.json b/package.json index 4718ed8..ca2dca5 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "ethjs-provider-signer": "^0.1.4", "ethjs-query": "^0.2.4", "ethjs-signer": "^0.1.1", - "express": "^4.15.2" + "express": "^4.15.2", + "web3": "^0.18.2" } }