diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..be6bb37 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +NET_ID=42 +RPC_URL=https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51 +PRIVATE_KEY= +MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4 +DEFAULT_GAS_PRICE=1 +GAS_ORACLE_URLS=https://www.etherchain.org/api/gasPriceOracle https://gasprice.poa.network/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index d491624..d06a9ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .vscode node_modules/ -env.json - +.env \ No newline at end of file diff --git a/README.md b/README.md index 355168b..dbe81be 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Relayer for Tornado mixer ## Setup 1. `npm i` -2. `cp env.json.example env.json` -3. Modify `env.json` as needed +2. `cp .env.example .env` +3. Modify `.env` as needed ## Run -1. `node index.js` +1. `npm run start` 2. `curl -X POST -H 'content-type:application/json' --data '' http://127.0.0.1:8000/relay` Relayer should return a transaction hash. diff --git a/config.js b/config.js new file mode 100644 index 0000000..2421eea --- /dev/null +++ b/config.js @@ -0,0 +1,10 @@ +require('dotenv').config() + +module.exports = { + netId: process.env.NET_ID || 42, + rpcUrl: process.env.RPC_URL || 'https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51', + privateKey: process.env.PRIVATE_KEY, + mixerAddress: process.env.MIXER_ADDRESS || '0x30AF2e92263C5387A8A689322BbfE60b6B0855C4', + defaultGasPrice: process.env.DEFAULT_GAS_PRICE || 1, + gasOracleUrls: process.env.GAS_ORACLE_URLS ? process.env.GAS_ORACLE_URLS.split(' ') : ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/'] +} \ No newline at end of file diff --git a/env.json.example b/env.json.example deleted file mode 100644 index d94c02d..0000000 --- a/env.json.example +++ /dev/null @@ -1,11 +0,0 @@ -{ - "netId": 42, - "rpcUrl": "https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51", - "privateKey": "", - "mixerAddress": "0x30AF2e92263C5387A8A689322BbfE60b6B0855C4", - "defaultGasPrice": 1, - "gasOracleUrls": [ - "https://www.etherchain.org/api/gasPriceOracle", - "https://gasprice.poa.network/" - ] -} diff --git a/index.js b/index.js index 23951ff..e8c5b30 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const express = require('express') const app = express() app.use(express.json()) -const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice } = require('./env.json') +const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice } = require('./config') const Web3 = require('web3') const web3 = new Web3(rpcUrl, null, { transactionConfirmationBlocks: 1 }) diff --git a/package-lock.json b/package-lock.json index 24ac880..9d0696f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -960,6 +960,11 @@ "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz", "integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=" }, + "dotenv": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz", + "integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==" + }, "drbg.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz", diff --git a/package.json b/package.json index fd713fe..9e50fab 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "Alexey Pertsev (https://peppersec.com)", "license": "MIT", "dependencies": { + "dotenv": "^8.0.0", "express": "^4.17.1", "node-fetch": "^2.6.0", "web3": "^1.0.0-beta.55", diff --git a/utils.js b/utils.js index 427097e..e626077 100644 --- a/utils.js +++ b/utils.js @@ -1,6 +1,6 @@ const fetch = require('node-fetch') const { isHexStrict } = require('web3-utils') -const { gasOracleUrls } = require('./env.json') +const { gasOracleUrls } = require('./config') async function fetchGasPrice({ gasPrices, oracleIndex = 0 }) { oracleIndex = (oracleIndex + 1) % gasOracleUrls.length