Get nonce from tx count
This commit is contained in:
parent
89484c8e4b
commit
8aad4cafae
40
index.js
40
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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue