Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions constants/contracts.js

This file was deleted.

20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const {program} = require('commander');
const express = require('express')
const path = require('path')
const cors = require('cors')
const bodyParser = require('body-parser');
const {initContract, claimTestToken} = require('./utils/contract')
const {validClaimArgs} = require('./utils/address')
const fs = require("fs");
const log = console.log.bind(console)
const port = 3089
const app = express()
Expand All @@ -30,6 +32,13 @@ app.get('/', (req, res) => {
res.sendFile(path.join('index.html'));
})

app.get('/tokens', (req, res) => {
log('receive a request get /tokens: ')
res.json({
tokens: allTokens
});
})

app.post('/api/claimTestToken', (req, res) => {
const params = req.body
log('receive a request: ', params)
Expand All @@ -49,9 +58,18 @@ app.post('/api/claimTestToken', (req, res) => {
)
})

const defaultConfig = './config.json';

let allTokens = [];

const main = async () => {
await initContract()
const {config} = program
.option('-c, --config <config>', 'config path', defaultConfig)
.parse(process.argv)
.opts()
const { tokens } = JSON.parse(fs.readFileSync(config).toString());
await initContract(tokens)
allTokens = Object.assign(tokens, []);

app.listen(port, () => {
log(`Faucet server listening at http://localhost:${port}`)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"commander": "^9.4.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"ethers": "^5.0.23",
Expand Down
7 changes: 3 additions & 4 deletions utils/contract.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
require('dotenv').config()
const ethers = require("ethers");
const erc20Abi = require("../constants/abi/erc20.json")
const {addresses} = require("../constants/contracts")

let provider, wallet
const contracts = {}

const initContract = async () => {
const initContract = async (tokens) => {
provider = await ethers.getDefaultProvider(process.env.RINKEBY_API);
wallet = new ethers.Wallet(process.env.RINKEBY_DEPLOYER_PRIVATE_KEY, provider)
Object.entries(addresses).forEach(([tokenName, tokenAddress]) => {
contracts[tokenAddress] = ethers.ContractFactory.getContract(tokenAddress, erc20Abi, wallet)
tokens.map((token) => {
contracts[token.address] = ethers.ContractFactory.getContract(token.address, erc20Abi, wallet)
})
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==

commander@^9.4.0:
version "9.4.0"
resolved "https://registry.npmmirror.com/commander/-/commander-9.4.0.tgz#bc4a40918fefe52e22450c111ecd6b7acce6f11c"
integrity sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==

[email protected]:
version "0.5.3"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd"
Expand Down