diff --git a/scripts/seeds.js b/scripts/seeds.js index ec98c4f..0f6d58e 100644 --- a/scripts/seeds.js +++ b/scripts/seeds.js @@ -1,48 +1,69 @@ -const path = require('path'); -const each = require('async-each-series'); +const path = require("path"); +const each = require("async-each-series"); -const seeds = require(path.join(__dirname, '..', '/config/seeds.js')); +const seeds = require(path.join(__dirname, "..", "/config/seeds.js")); const { ethers } = require("hardhat"); -const Kredits = require('../lib/kredits'); +const Kredits = require("../lib/kredits"); async function main() { - kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner()) + kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner()); await kredits.init(); - let fundingAmount = '2'; + const address = await hre.ethers.provider.getSigner().getAddress(); + console.log(`Sender account: ${address}`); + + let fundingAmount = "2"; each(seeds.funds, (address, next) => { console.log(`funding ${address} with 2 ETH`); try { hre.ethers.provider.getSigner().sendTransaction({ to: address, - value: hre.ethers.utils.parseEther(fundingAmount) + value: hre.ethers.utils.parseEther(fundingAmount), }); - } catch(e) { - console.log('FAILED:', e); + } catch (e) { + console.log("FAILED:", e); } next(); }); - each(seeds.contractCalls, (call, next) => { - let [contractName, method, args] = call; - let contractWrapper = kredits[contractName]; - let func; - if (contractWrapper[method]) { - func = contractWrapper[method]; - } else { - func = contractWrapper.contract[method]; + each( + seeds.contractCalls, + (call, next) => { + let [contractName, method, args] = call; + let contractWrapper = kredits[contractName]; + let func; + if (contractWrapper[method]) { + func = contractWrapper[method]; + } else { + func = contractWrapper.contract[method]; + } + func + .apply(contractWrapper, args) + .then((result) => { + console.log( + `[OK] kredits.${contractName}.${method}(${JSON.stringify( + args + )}) => ${result.hash}` + ); + result.wait().then((r) => { + next(); + }); + }) + .catch((error) => { + console.log( + `[FAILED] kredits.${contractName}.${method}(${JSON.stringify( + args + )})` + ); + console.log(`Error: ${error.message}`); + next(); + }); + }, + () => { + console.log("\nDone!"); } - func.apply(contractWrapper, args).then((result) => { - console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`); - next(); - }).catch((error) => { - console.log(`[FAILED] kredits.${contractName}.${method}(${JSON.stringify(args)})`); - console.log(`Error: ${error.message}`); - next(); - }); - }, () => { console.log("\nDone!") }); - + ); } main();