Get nonce from tx count

This commit is contained in:
Jorge Izquierdo 2017-03-10 10:01:43 +01:00
parent 89484c8e4b
commit 8aad4cafae
2 changed files with 21 additions and 22 deletions

View File

@ -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

View File

@ -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"
}
}