diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..93c5c92 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +walletAddress= +walletPrivateKey= +infuraProjectId= diff --git a/.gitignore b/.gitignore index 646ac51..047173c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store node_modules/ +.env 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;