From 4a108206fce1d5f11f27eda5b4298c6de0432103 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Jan 2021 10:57:47 +0100 Subject: [PATCH 1/2] add environment variables --- .env.example | 3 +++ .gitignore | 1 + package-lock.json | 5 +++++ package.json | 1 + server.js | 8 +++++--- 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..55a5b26 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +walletAddress= +walletPrivateKey= +infuraProjectId= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 646ac51..8e36a30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store node_modules/ +.env \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cb02dd1..e330863 100644 --- a/package-lock.json +++ b/package-lock.json @@ -640,6 +640,11 @@ "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz", "integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=" }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "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 5c937f9..f870603 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "", "license": "MIT", "dependencies": { + "dotenv": "^8.2.0", "express": "^4.17.1", "web3": "^1.2.6" } diff --git a/server.js b/server.js index 1ba7b6a..968f751 100644 --- a/server.js +++ b/server.js @@ -1,13 +1,15 @@ +require("dotenv").config(); // this ensures process.env. ... contains your .env file configuration values + const express = require('express'); const bodyParser = require('body-parser'); const Web3 = require('web3'); const config = require('./config.json'); -const walletPrivateKey = process.env.walletPrivateKey; -const web3 = new Web3('https://mainnet.infura.io/v3/_your_api_key_here_'); +const walletPrivateKey = process.env.walletPrivateKey; // make sure this is provided in your .env file +const web3 = new Web3(`https://mainnet.infura.io/v3/${process.env.infuraProjectId}`); web3.eth.accounts.wallet.add(walletPrivateKey); -const myWalletAddress = web3.eth.accounts.wallet[0].address; +const myWalletAddress = process.env.walletAddress const cEthAddress = config.cEthAddress; const cEthAbi = config.cEthAbi; From 6a411afb17aae3ba3f0fb94ef4c452838569caa4 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Jan 2021 10:59:22 +0100 Subject: [PATCH 2/2] fix lint warnings --- .env.example | 2 +- .gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 55a5b26..93c5c92 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ walletAddress= walletPrivateKey= -infuraProjectId= \ No newline at end of file +infuraProjectId= diff --git a/.gitignore b/.gitignore index 8e36a30..047173c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .DS_Store node_modules/ -.env \ No newline at end of file +.env