From da8ec6e57aeffebe627573fc9ec9a48b4057f900 Mon Sep 17 00:00:00 2001 From: Armando Andini Date: Fri, 27 Aug 2021 15:15:32 -0300 Subject: [PATCH] Ropsten setup --- faucet/.env.example | 2 ++ faucet/hardhat.config.ts | 9 +++++++++ faucet/package-lock.json | 16 ++++++++++++++++ faucet/package.json | 1 + faucet/scripts/faucet_deploy.js | 12 ++++++++---- faucet/scripts/faucet_deposit.ts | 22 ++++++++++++++++++++++ faucet/scripts/faucet_withdraw.ts | 23 +++++++++++++++++++++++ 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 faucet/.env.example create mode 100644 faucet/scripts/faucet_deposit.ts create mode 100644 faucet/scripts/faucet_withdraw.ts diff --git a/faucet/.env.example b/faucet/.env.example new file mode 100644 index 0000000..e580370 --- /dev/null +++ b/faucet/.env.example @@ -0,0 +1,2 @@ +ALCHEMY_API_KEY= +ROPSTEN_PRIVATE_KEY= \ No newline at end of file diff --git a/faucet/hardhat.config.ts b/faucet/hardhat.config.ts index d48ef3b..bb480fd 100644 --- a/faucet/hardhat.config.ts +++ b/faucet/hardhat.config.ts @@ -1,6 +1,9 @@ import { task } from "hardhat/config"; import "@nomiclabs/hardhat-waffle"; +import dotenv from 'dotenv' +dotenv.config() + // This is a sample Hardhat task. To learn how to create your own go to // https://hardhat.org/guides/create-task.html task("accounts", "Prints the list of accounts", async (args, hre) => { @@ -16,4 +19,10 @@ task("accounts", "Prints the list of accounts", async (args, hre) => { export default { solidity: "0.8.7", + networks: { + ropsten: { + url: `https://eth-ropsten.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`, + accounts: [`0x${process.env.ROPSTEN_PRIVATE_KEY}`], + }, + }, }; diff --git a/faucet/package-lock.json b/faucet/package-lock.json index ff0fbcd..480e304 100644 --- a/faucet/package-lock.json +++ b/faucet/package-lock.json @@ -12,6 +12,7 @@ "@types/mocha": "^9.0.0", "@types/node": "^16.7.1", "chai": "^4.3.4", + "dotenv": "^10.0.0", "ethereum-waffle": "^3.4.0", "ethers": "^5.4.5", "hardhat": "^2.6.1", @@ -2457,6 +2458,15 @@ "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==", "dev": true }, + "node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -17763,6 +17773,12 @@ "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==", "dev": true }, + "dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "dev": true + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", diff --git a/faucet/package.json b/faucet/package.json index 7868064..df44189 100644 --- a/faucet/package.json +++ b/faucet/package.json @@ -7,6 +7,7 @@ "@types/mocha": "^9.0.0", "@types/node": "^16.7.1", "chai": "^4.3.4", + "dotenv": "^10.0.0", "ethereum-waffle": "^3.4.0", "ethers": "^5.4.5", "hardhat": "^2.6.1", diff --git a/faucet/scripts/faucet_deploy.js b/faucet/scripts/faucet_deploy.js index 07be5c2..425210e 100644 --- a/faucet/scripts/faucet_deploy.js +++ b/faucet/scripts/faucet_deploy.js @@ -1,12 +1,16 @@ const hre = require("hardhat"); async function main() { - const faucetFactory = await hre.ethers.getContractFactory("Faucet"); - const faucetContract = await faucetFactory.deploy(); + const [deployer] = await ethers.getSigners(); - await faucetContract.deployed(); + console.log("Deploying contracts with the account:", deployer.address); - console.log("Contract deployed to:", faucetContract.address); + console.log("Account balance:", (await deployer.getBalance()).toString()); + + const Faucet = await ethers.getContractFactory("Faucet"); + const faucet = await Faucet.deploy(); + + console.log("Faucet address:", faucet.address); } main() diff --git a/faucet/scripts/faucet_deposit.ts b/faucet/scripts/faucet_deposit.ts new file mode 100644 index 0000000..886cd59 --- /dev/null +++ b/faucet/scripts/faucet_deposit.ts @@ -0,0 +1,22 @@ +import { TransactionResponse } from '@ethersproject/abstract-provider'; +import { providers, Signer } from 'ethers'; +import {ethers} from 'hardhat' + +const contractAddress = '0x252ccddA5cb868f5fB69120985b332c11dB15bE7'; + +async function main() { + const [account] = await ethers.getSigners(); + + const tx = await account.sendTransaction({to: contractAddress, value: ethers.utils.parseEther('0.01')}) + console.log('Transaction sent') + + const receipt = await tx.wait() as any + console.log('Transaction confirmed') +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/faucet/scripts/faucet_withdraw.ts b/faucet/scripts/faucet_withdraw.ts new file mode 100644 index 0000000..1774cb4 --- /dev/null +++ b/faucet/scripts/faucet_withdraw.ts @@ -0,0 +1,23 @@ +import { TransactionResponse } from '@ethersproject/abstract-provider'; +import { providers, Signer } from 'ethers'; +import {ethers} from 'hardhat' + +const contractAddress = '0x252ccddA5cb868f5fB69120985b332c11dB15bE7'; + +async function main() { + const factory = await ethers.getContractFactory('Faucet') + const contract = factory.attach(contractAddress) + + const tx = await contract.withdraw(ethers.utils.parseEther('0.01')) as TransactionResponse + console.log('Transaction sent') + + const receipt = await tx.wait() as any + console.log('Transaction confirmed') +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + });