commit f52d78da73b75e8a50f26ef0b938fc6132627a55 Author: Jorge Izquierdo Date: Tue Mar 7 12:24:01 2017 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..58ca644 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM node:7-onbuild + +ENV PORT 8080 +EXPOSE 8080 diff --git a/index.js b/index.js new file mode 100644 index 0000000..9c7c12c --- /dev/null +++ b/index.js @@ -0,0 +1,45 @@ +const SignerProvider = require('ethjs-provider-signer'); +const sign = require('ethjs-signer').sign; +const Eth = require('ethjs-query'); + +const address = process.env.ADDRESS + +const provider = new SignerProvider(process.env.NODE, { + signTransaction: (rawTx, cb) => cb(null, sign(rawTx, process.env.KEY)), + accounts: (cb) => cb(null, [address]), +}); +const eth = new Eth(provider); + +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: 21500, + value: 1e16, + 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 +app.listen(port, function(){ + console.log('Faucet listening on port', port); +}); diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..38f8cae --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,25 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/Cellar/node/7.4.0/bin/node', +1 verbose cli '/usr/local/bin/npm', +1 verbose cli 'start' ] +2 info using npm@4.0.5 +3 info using node@v7.4.0 +4 verbose stack Error: missing script: start +4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19) +4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5 +4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 +4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45) +4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3) +4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5) +4 verbose stack at ReadFileContext. (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:295:20) +4 verbose stack at ReadFileContext.callback (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16) +4 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:336:13) +5 verbose cwd /Users/jorge/provident/kovan-faucet +6 error Darwin 16.4.0 +7 error argv "/usr/local/Cellar/node/7.4.0/bin/node" "/usr/local/bin/npm" "start" +8 error node v7.4.0 +9 error npm v4.0.5 +10 error missing script: start +11 error If you need help, you may report this error at: +11 error +12 verbose exit [ 1, true ] diff --git a/package.json b/package.json new file mode 100644 index 0000000..4718ed8 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "kovan-faucet", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "cors": "^2.8.1", + "ethjs-provider-signer": "^0.1.4", + "ethjs-query": "^0.2.4", + "ethjs-signer": "^0.1.1", + "express": "^4.15.2" + } +}