diff --git a/packages/hardhat/access_keys.js b/packages/hardhat/access_keys.js new file mode 100644 index 0000000..3bf1094 --- /dev/null +++ b/packages/hardhat/access_keys.js @@ -0,0 +1,13 @@ +const infuraRinkeby = + "https://rinkeby.infura.io/v3/1609258d29dd4002beca55e5bb6bf73c"; + +const rinkebyKey = + ""; + +const rinkebyContractAddress = "0x0bE718F6a4F2377F3Fc8d73609AF15B440c90128"; + +module.exports = { + infuraRinkeby, + rinkebyKey, + rinkebyContractAddress +}; diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index ab6e3cd..d86102a 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -32,613 +32,613 @@ const defaultNetwork = "localhost"; const mainnetGwei = 21; function mnemonic() { - try { - return fs.readFileSync("./mnemonic.txt").toString().trim(); - } catch (e) { - if (defaultNetwork !== "localhost") { - console.log( - "☢️ WARNING: No mnemonic file created for a deploy account. Try `yarn run generate` and then `yarn run account`." - ); - } - } - return ""; + try { + return fs.readFileSync("./mnemonic.txt").toString().trim(); + } catch (e) { + if (defaultNetwork !== "localhost") { + console.log( + "☢️ WARNING: No mnemonic file created for a deploy account. Try `yarn run generate` and then `yarn run account`." + ); + } + } + return ""; } module.exports = { - defaultNetwork, - - /** - * gas reporter configuration that let's you know - * an estimate of gas for contract deployments and function calls - * More here: https://hardhat.org/plugins/hardhat-gas-reporter.html - */ - gasReporter: { - currency: "USD", - coinmarketcap: process.env.COINMARKETCAP || null, - }, - - // if you want to deploy to a testnet, mainnet, or xdai, you will need to configure: - // 1. An Infura key (or similar) - // 2. A private key for the deployer - // DON'T PUSH THESE HERE!!! - // An `example.env` has been provided in the Hardhat root. Copy it and rename it `.env` - // Follow the directions, and uncomment the network you wish to deploy to. - - networks: { - localhost: { - url: "http://localhost:8545", - /* + defaultNetwork, + + /** + * gas reporter configuration that let's you know + * an estimate of gas for contract deployments and function calls + * More here: https://hardhat.org/plugins/hardhat-gas-reporter.html + */ + gasReporter: { + currency: "USD", + coinmarketcap: process.env.COINMARKETCAP || null + }, + + // if you want to deploy to a testnet, mainnet, or xdai, you will need to configure: + // 1. An Infura key (or similar) + // 2. A private key for the deployer + // DON'T PUSH THESE HERE!!! + // An `example.env` has been provided in the Hardhat root. Copy it and rename it `.env` + // Follow the directions, and uncomment the network you wish to deploy to. + + networks: { + localhost: { + url: "http://localhost:8545" + /* notice no mnemonic here? it will just use account 0 of the hardhat node to deploy (you can put in a mnemonic here to set the deployer locally) */ - }, - rinkeby: { - url: "https://rinkeby.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/eth/rinkeby", // <---- YOUR MORALIS ID! (not limited to infura) - accounts: { - mnemonic: mnemonic(), - }, - }, - kovan: { - url: "https://kovan.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/eth/kovan", // <---- YOUR MORALIS ID! (not limited to infura) - accounts: { - mnemonic: mnemonic(), - }, - }, - mainnet: { - url: "https://mainnet.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXXXX/eth/mainnet", // <---- YOUR MORALIS ID! (not limited to infura) - gasPrice: mainnetGwei * 1000000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - ropsten: { - url: "https://ropsten.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXXXX/eth/ropsten",// <---- YOUR MORALIS ID! (not limited to infura) - accounts: { - mnemonic: mnemonic(), - }, - }, - goerli: { - url: "https://goerli.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXXXX/eth/goerli", // <---- YOUR MORALIS ID! (not limited to infura) - accounts: { - mnemonic: mnemonic(), - }, - }, - xdai: { - url: "https://rpc.xdaichain.com/", - gasPrice: 1000000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - fantom: { - url: "https://rpcapi.fantom.network", - gasPrice: 1000000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - testnetFantom: { - url: "https://rpc.testnet.fantom.network", - gasPrice: 1000000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - polygon: { - url: "https://polygon-rpc.com", - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXx/polygon/mainnet", // <---- YOUR MORALIS ID! (not limited to infura) - gasPrice: 3200000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - mumbai: { - url: "https://rpc-mumbai.maticvigil.com", - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/polygon/mumbai", // <---- YOUR MORALIS ID! (not limited to infura) - gasPrice: 3200000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - matic: { - url: "https://rpc-mainnet.maticvigil.com/", - gasPrice: 1000000000, - accounts: { - mnemonic: mnemonic(), - }, - }, - optimism: { - url: "https://mainnet.optimism.io", - accounts: { - mnemonic: mnemonic(), - }, - companionNetworks: { - l1: "mainnet", - }, - }, - kovanOptimism: { - url: "https://kovan.optimism.io", - accounts: { - mnemonic: mnemonic(), - }, - companionNetworks: { - l1: "kovan", - }, - }, - localOptimism: { - url: "http://localhost:8545", - accounts: { - mnemonic: mnemonic(), - }, - companionNetworks: { - l1: "localOptimismL1", - }, - }, - localOptimismL1: { - url: "http://localhost:9545", - gasPrice: 0, - accounts: { - mnemonic: mnemonic(), - }, - companionNetworks: { - l2: "localOptimism", - }, - }, - localAvalanche: { - url: "http://localhost:9650/ext/bc/C/rpc", - gasPrice: 225000000000, - chainId: 43112, - accounts: { - mnemonic: mnemonic(), - }, - }, - fujiAvalanche: { - url: "https://api.avax-test.network/ext/bc/C/rpc", - gasPrice: 225000000000, - chainId: 43113, - accounts: { - mnemonic: mnemonic(), - }, - }, - mainnetAvalanche: { - url: "https://api.avax.network/ext/bc/C/rpc", - gasPrice: 225000000000, - chainId: 43114, - accounts: { - mnemonic: mnemonic(), - }, - }, - testnetHarmony: { - url: "https://api.s0.b.hmny.io", - gasPrice: 1000000000, - chainId: 1666700000, - accounts: { - mnemonic: mnemonic(), - }, - }, - mainnetHarmony: { - url: "https://api.harmony.one", - gasPrice: 1000000000, - chainId: 1666600000, - accounts: { - mnemonic: mnemonic(), - }, - }, - moonbeam: { - url: 'https://rpc.api.moonbeam.network', - chainId: 1284, - accounts: { - mnemonic: mnemonic(), - }, - }, - moonriver: { - url: 'https://rpc.api.moonriver.moonbeam.network', - chainId: 1285, - accounts: { - mnemonic: mnemonic(), - }, - }, - moonbaseAlpha: { - url: 'https://rpc.api.moonbase.moonbeam.network', - chainId: 1287, - accounts: { - mnemonic: mnemonic(), - }, - }, - moonbeamDevNode: { - url: 'http://127.0.0.1:9933', - chainId: 1281, - accounts: { - mnemonic: mnemonic(), - }, - }, - godwoken: { - url: 'https://godwoken-testnet-v1.ckbapp.dev', - chainId: 71401, - accounts: { - mnemonic: mnemonic(), - }, - }, - arbitrum: { - url: 'https://arb1.arbitrum.io/rpc', - chainId: 42161, - accounts: { - mnemonic: mnemonic(), - }, - }, - rinkebyArbitrum: { - url: 'https://rinkeby.arbitrum.io/rpc', - chainId: 421611, - accounts: { - mnemonic: mnemonic(), - }, - }, - devnetArbitrum: { - url: 'https://nitro-devnet.arbitrum.io/rpc', - chainId: 421612, - accounts: { - mnemonic: mnemonic(), - }, - }, - }, - solidity: { - compilers: [ - { - version: "0.8.4", - settings: { - optimizer: { - enabled: true, - runs: 200, - }, - }, - }, - { - version: "0.6.7", - settings: { - optimizer: { - enabled: true, - runs: 200, - }, - }, - }, - ], - }, - ovm: { - solcVersion: "0.7.6", - }, - namedAccounts: { - deployer: { - default: 0, // here this will by default take the first account as deployer - }, - }, - etherscan: { - apiKey: { - mainnet: "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW", - // add other network's API key here - }, - }, - abiExporter: { - path: "../react-app/src/contracts/ABI", - runOnCompile: true, - clear: true, - flat: true, - only: [], - spacing: 2, - pretty: false, - }, + }, + rinkeby: { + url: "", // <---- YOUR INFURA ID! (or it won't work) + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/eth/rinkeby", // <---- YOUR MORALIS ID! (not limited to infura) + accounts: [ + "" + ] + }, + kovan: { + url: "https://kovan.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/eth/kovan", // <---- YOUR MORALIS ID! (not limited to infura) + accounts: { + mnemonic: mnemonic() + } + }, + mainnet: { + url: "https://mainnet.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXXXX/eth/mainnet", // <---- YOUR MORALIS ID! (not limited to infura) + gasPrice: mainnetGwei * 1000000000, + accounts: { + mnemonic: mnemonic() + } + }, + ropsten: { + url: "https://ropsten.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXXXX/eth/ropsten",// <---- YOUR MORALIS ID! (not limited to infura) + accounts: { + mnemonic: mnemonic() + } + }, + goerli: { + url: "https://goerli.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXXXX/eth/goerli", // <---- YOUR MORALIS ID! (not limited to infura) + accounts: { + mnemonic: mnemonic() + } + }, + xdai: { + url: "https://rpc.xdaichain.com/", + gasPrice: 1000000000, + accounts: { + mnemonic: mnemonic() + } + }, + fantom: { + url: "https://rpcapi.fantom.network", + gasPrice: 1000000000, + accounts: { + mnemonic: mnemonic() + } + }, + testnetFantom: { + url: "https://rpc.testnet.fantom.network", + gasPrice: 1000000000, + accounts: { + mnemonic: mnemonic() + } + }, + polygon: { + url: "https://polygon-rpc.com", + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXx/polygon/mainnet", // <---- YOUR MORALIS ID! (not limited to infura) + gasPrice: 3200000000, + accounts: { + mnemonic: mnemonic() + } + }, + mumbai: { + url: "https://rpc-mumbai.maticvigil.com", + // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/polygon/mumbai", // <---- YOUR MORALIS ID! (not limited to infura) + gasPrice: 3200000000, + accounts: { + mnemonic: mnemonic() + } + }, + matic: { + url: "https://rpc-mainnet.maticvigil.com/", + gasPrice: 1000000000, + accounts: { + mnemonic: mnemonic() + } + }, + optimism: { + url: "https://mainnet.optimism.io", + accounts: { + mnemonic: mnemonic() + }, + companionNetworks: { + l1: "mainnet" + } + }, + kovanOptimism: { + url: "https://kovan.optimism.io", + accounts: { + mnemonic: mnemonic() + }, + companionNetworks: { + l1: "kovan" + } + }, + localOptimism: { + url: "http://localhost:8545", + accounts: { + mnemonic: mnemonic() + }, + companionNetworks: { + l1: "localOptimismL1" + } + }, + localOptimismL1: { + url: "http://localhost:9545", + gasPrice: 0, + accounts: { + mnemonic: mnemonic() + }, + companionNetworks: { + l2: "localOptimism" + } + }, + localAvalanche: { + url: "http://localhost:9650/ext/bc/C/rpc", + gasPrice: 225000000000, + chainId: 43112, + accounts: { + mnemonic: mnemonic() + } + }, + fujiAvalanche: { + url: "https://api.avax-test.network/ext/bc/C/rpc", + gasPrice: 225000000000, + chainId: 43113, + accounts: { + mnemonic: mnemonic() + } + }, + mainnetAvalanche: { + url: "https://api.avax.network/ext/bc/C/rpc", + gasPrice: 225000000000, + chainId: 43114, + accounts: { + mnemonic: mnemonic() + } + }, + testnetHarmony: { + url: "https://api.s0.b.hmny.io", + gasPrice: 1000000000, + chainId: 1666700000, + accounts: { + mnemonic: mnemonic() + } + }, + mainnetHarmony: { + url: "https://api.harmony.one", + gasPrice: 1000000000, + chainId: 1666600000, + accounts: { + mnemonic: mnemonic() + } + }, + moonbeam: { + url: "https://rpc.api.moonbeam.network", + chainId: 1284, + accounts: { + mnemonic: mnemonic() + } + }, + moonriver: { + url: "https://rpc.api.moonriver.moonbeam.network", + chainId: 1285, + accounts: { + mnemonic: mnemonic() + } + }, + moonbaseAlpha: { + url: "https://rpc.api.moonbase.moonbeam.network", + chainId: 1287, + accounts: { + mnemonic: mnemonic() + } + }, + moonbeamDevNode: { + url: "http://127.0.0.1:9933", + chainId: 1281, + accounts: { + mnemonic: mnemonic() + } + }, + godwoken: { + url: "https://godwoken-testnet-v1.ckbapp.dev", + chainId: 71401, + accounts: { + mnemonic: mnemonic() + } + }, + arbitrum: { + url: "https://arb1.arbitrum.io/rpc", + chainId: 42161, + accounts: { + mnemonic: mnemonic() + } + }, + rinkebyArbitrum: { + url: "https://rinkeby.arbitrum.io/rpc", + chainId: 421611, + accounts: { + mnemonic: mnemonic() + } + }, + devnetArbitrum: { + url: "https://nitro-devnet.arbitrum.io/rpc", + chainId: 421612, + accounts: { + mnemonic: mnemonic() + } + } + }, + solidity: { + compilers: [ + { + version: "0.8.4", + settings: { + optimizer: { + enabled: true, + runs: 200 + } + } + }, + { + version: "0.6.7", + settings: { + optimizer: { + enabled: true, + runs: 200 + } + } + } + ] + }, + ovm: { + solcVersion: "0.7.6" + }, + namedAccounts: { + deployer: { + default: 0 // here this will by default take the first account as deployer + } + }, + etherscan: { + apiKey: { + mainnet: "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW" + // add other network's API key here + } + }, + abiExporter: { + path: "../react-app/src/contracts/ABI", + runOnCompile: true, + clear: true, + flat: true, + only: [], + spacing: 2, + pretty: false + } }; const DEBUG = false; function debug(text) { - if (DEBUG) { - console.log(text); - } + if (DEBUG) { + console.log(text); + } } task("wallet", "Create a wallet (pk) link", async (_, { ethers }) => { - const randomWallet = ethers.Wallet.createRandom(); - const privateKey = randomWallet._signingKey().privateKey; - console.log("🔐 WALLET Generated as " + randomWallet.address + ""); - console.log("🔗 http://localhost:3000/pk#" + privateKey); + const randomWallet = ethers.Wallet.createRandom(); + const privateKey = randomWallet._signingKey().privateKey; + console.log("🔐 WALLET Generated as " + randomWallet.address + ""); + console.log("🔗 http://localhost:3000/pk#" + privateKey); }); task("fundedwallet", "Create a wallet (pk) link and fund it with deployer?") - .addOptionalParam( - "amount", - "Amount of ETH to send to wallet after generating" - ) - .addOptionalParam("url", "URL to add pk to") - .setAction(async (taskArgs, { network, ethers }) => { - const randomWallet = ethers.Wallet.createRandom(); - const privateKey = randomWallet._signingKey().privateKey; - console.log("🔐 WALLET Generated as " + randomWallet.address + ""); - const url = taskArgs.url ? taskArgs.url : "http://localhost:3000"; - - let localDeployerMnemonic; - try { - localDeployerMnemonic = fs.readFileSync("./mnemonic.txt"); - localDeployerMnemonic = localDeployerMnemonic.toString().trim(); - } catch (e) { - /* do nothing - this file isn't always there */ - } - - const amount = taskArgs.amount ? taskArgs.amount : "0.01"; - const tx = { - to: randomWallet.address, - value: ethers.utils.parseEther(amount), - }; - - // SEND USING LOCAL DEPLOYER MNEMONIC IF THERE IS ONE - // IF NOT SEND USING LOCAL HARDHAT NODE: - if (localDeployerMnemonic) { - let deployerWallet = new ethers.Wallet.fromMnemonic( - localDeployerMnemonic - ); - deployerWallet = deployerWallet.connect(ethers.provider); - console.log( - "💵 Sending " + - amount + - " ETH to " + - randomWallet.address + - " using deployer account" - ); - const sendresult = await deployerWallet.sendTransaction(tx); - console.log("\n" + url + "/pk#" + privateKey + "\n"); - } else { - console.log( - "💵 Sending " + - amount + - " ETH to " + - randomWallet.address + - " using local node" - ); - console.log("\n" + url + "/pk#" + privateKey + "\n"); - return send(ethers.provider.getSigner(), tx); - } - }); + .addOptionalParam( + "amount", + "Amount of ETH to send to wallet after generating" + ) + .addOptionalParam("url", "URL to add pk to") + .setAction(async (taskArgs, { network, ethers }) => { + const randomWallet = ethers.Wallet.createRandom(); + const privateKey = randomWallet._signingKey().privateKey; + console.log("🔐 WALLET Generated as " + randomWallet.address + ""); + const url = taskArgs.url ? taskArgs.url : "http://localhost:3000"; + + let localDeployerMnemonic; + try { + localDeployerMnemonic = fs.readFileSync("./mnemonic.txt"); + localDeployerMnemonic = localDeployerMnemonic.toString().trim(); + } catch (e) { + /* do nothing - this file isn't always there */ + } + + const amount = taskArgs.amount ? taskArgs.amount : "0.01"; + const tx = { + to: randomWallet.address, + value: ethers.utils.parseEther(amount) + }; + + // SEND USING LOCAL DEPLOYER MNEMONIC IF THERE IS ONE + // IF NOT SEND USING LOCAL HARDHAT NODE: + if (localDeployerMnemonic) { + let deployerWallet = new ethers.Wallet.fromMnemonic( + localDeployerMnemonic + ); + deployerWallet = deployerWallet.connect(ethers.provider); + console.log( + "💵 Sending " + + amount + + " ETH to " + + randomWallet.address + + " using deployer account" + ); + const sendresult = await deployerWallet.sendTransaction(tx); + console.log("\n" + url + "/pk#" + privateKey + "\n"); + } else { + console.log( + "💵 Sending " + + amount + + " ETH to " + + randomWallet.address + + " using local node" + ); + console.log("\n" + url + "/pk#" + privateKey + "\n"); + return send(ethers.provider.getSigner(), tx); + } + }); task( - "generate", - "Create a mnemonic for builder deploys", - async (_, { ethers }) => { - const bip39 = require("bip39"); - const hdkey = require("ethereumjs-wallet/hdkey"); - const mnemonic = bip39.generateMnemonic(); - if (DEBUG) console.log("mnemonic", mnemonic); - const seed = await bip39.mnemonicToSeed(mnemonic); - if (DEBUG) console.log("seed", seed); - const hdwallet = hdkey.fromMasterSeed(seed); - const wallet_hdpath = "m/44'/60'/0'/0/"; - const account_index = 0; - const fullPath = wallet_hdpath + account_index; - if (DEBUG) console.log("fullPath", fullPath); - const wallet = hdwallet.derivePath(fullPath).getWallet(); - const privateKey = "0x" + wallet._privKey.toString("hex"); - if (DEBUG) console.log("privateKey", privateKey); - const EthUtil = require("ethereumjs-util"); - const address = - "0x" + EthUtil.privateToAddress(wallet._privKey).toString("hex"); - console.log( - "🔐 Account Generated as " + - address + - " and set as mnemonic in packages/hardhat" - ); - console.log( - "💬 Use 'yarn run account' to get more information about the deployment account." - ); - - fs.writeFileSync("./" + address + ".txt", mnemonic.toString()); - fs.writeFileSync("./mnemonic.txt", mnemonic.toString()); - } + "generate", + "Create a mnemonic for builder deploys", + async (_, { ethers }) => { + const bip39 = require("bip39"); + const hdkey = require("ethereumjs-wallet/hdkey"); + const mnemonic = bip39.generateMnemonic(); + if (DEBUG) console.log("mnemonic", mnemonic); + const seed = await bip39.mnemonicToSeed(mnemonic); + if (DEBUG) console.log("seed", seed); + const hdwallet = hdkey.fromMasterSeed(seed); + const wallet_hdpath = "m/44'/60'/0'/0/"; + const account_index = 0; + const fullPath = wallet_hdpath + account_index; + if (DEBUG) console.log("fullPath", fullPath); + const wallet = hdwallet.derivePath(fullPath).getWallet(); + const privateKey = "0x" + wallet._privKey.toString("hex"); + if (DEBUG) console.log("privateKey", privateKey); + const EthUtil = require("ethereumjs-util"); + const address = + "0x" + EthUtil.privateToAddress(wallet._privKey).toString("hex"); + console.log( + "🔐 Account Generated as " + + address + + " and set as mnemonic in packages/hardhat" + ); + console.log( + "💬 Use 'yarn run account' to get more information about the deployment account." + ); + + fs.writeFileSync("./" + address + ".txt", mnemonic.toString()); + fs.writeFileSync("./mnemonic.txt", mnemonic.toString()); + } ); task( - "mineContractAddress", - "Looks for a deployer account that will give leading zeros" + "mineContractAddress", + "Looks for a deployer account that will give leading zeros" ) - .addParam("searchFor", "String to search for") - .setAction(async (taskArgs, { network, ethers }) => { - let contract_address = ""; - let address; - - const bip39 = require("bip39"); - const hdkey = require("ethereumjs-wallet/hdkey"); - - let mnemonic = ""; - while (contract_address.indexOf(taskArgs.searchFor) != 0) { - mnemonic = bip39.generateMnemonic(); - if (DEBUG) console.log("mnemonic", mnemonic); - const seed = await bip39.mnemonicToSeed(mnemonic); - if (DEBUG) console.log("seed", seed); - const hdwallet = hdkey.fromMasterSeed(seed); - const wallet_hdpath = "m/44'/60'/0'/0/"; - const account_index = 0; - const fullPath = wallet_hdpath + account_index; - if (DEBUG) console.log("fullPath", fullPath); - const wallet = hdwallet.derivePath(fullPath).getWallet(); - const privateKey = "0x" + wallet._privKey.toString("hex"); - if (DEBUG) console.log("privateKey", privateKey); - const EthUtil = require("ethereumjs-util"); - address = - "0x" + EthUtil.privateToAddress(wallet._privKey).toString("hex"); - - const rlp = require("rlp"); - const keccak = require("keccak"); - - const nonce = 0x00; // The nonce must be a hex literal! - const sender = address; - - const input_arr = [sender, nonce]; - const rlp_encoded = rlp.encode(input_arr); - - const contract_address_long = keccak("keccak256") - .update(rlp_encoded) - .digest("hex"); - - contract_address = contract_address_long.substring(24); // Trim the first 24 characters. - } - - console.log( - "⛏ Account Mined as " + - address + - " and set as mnemonic in packages/hardhat" - ); - console.log( - "📜 This will create the first contract: " + - chalk.magenta("0x" + contract_address) - ); - console.log( - "💬 Use 'yarn run account' to get more information about the deployment account." - ); - - fs.writeFileSync( - "./" + address + "_produces" + contract_address + ".txt", - mnemonic.toString() - ); - fs.writeFileSync("./mnemonic.txt", mnemonic.toString()); - }); + .addParam("searchFor", "String to search for") + .setAction(async (taskArgs, { network, ethers }) => { + let contract_address = ""; + let address; + + const bip39 = require("bip39"); + const hdkey = require("ethereumjs-wallet/hdkey"); + + let mnemonic = ""; + while (contract_address.indexOf(taskArgs.searchFor) != 0) { + mnemonic = bip39.generateMnemonic(); + if (DEBUG) console.log("mnemonic", mnemonic); + const seed = await bip39.mnemonicToSeed(mnemonic); + if (DEBUG) console.log("seed", seed); + const hdwallet = hdkey.fromMasterSeed(seed); + const wallet_hdpath = "m/44'/60'/0'/0/"; + const account_index = 0; + const fullPath = wallet_hdpath + account_index; + if (DEBUG) console.log("fullPath", fullPath); + const wallet = hdwallet.derivePath(fullPath).getWallet(); + const privateKey = "0x" + wallet._privKey.toString("hex"); + if (DEBUG) console.log("privateKey", privateKey); + const EthUtil = require("ethereumjs-util"); + address = + "0x" + EthUtil.privateToAddress(wallet._privKey).toString("hex"); + + const rlp = require("rlp"); + const keccak = require("keccak"); + + const nonce = 0x00; // The nonce must be a hex literal! + const sender = address; + + const input_arr = [sender, nonce]; + const rlp_encoded = rlp.encode(input_arr); + + const contract_address_long = keccak("keccak256") + .update(rlp_encoded) + .digest("hex"); + + contract_address = contract_address_long.substring(24); // Trim the first 24 characters. + } + + console.log( + "⛏ Account Mined as " + + address + + " and set as mnemonic in packages/hardhat" + ); + console.log( + "📜 This will create the first contract: " + + chalk.magenta("0x" + contract_address) + ); + console.log( + "💬 Use 'yarn run account' to get more information about the deployment account." + ); + + fs.writeFileSync( + "./" + address + "_produces" + contract_address + ".txt", + mnemonic.toString() + ); + fs.writeFileSync("./mnemonic.txt", mnemonic.toString()); + }); task( - "account", - "Get balance informations for the deployment account.", - async (_, { ethers }) => { - const hdkey = require("ethereumjs-wallet/hdkey"); - const bip39 = require("bip39"); - try { - const mnemonic = fs.readFileSync("./mnemonic.txt").toString().trim(); - if (DEBUG) console.log("mnemonic", mnemonic); - const seed = await bip39.mnemonicToSeed(mnemonic); - if (DEBUG) console.log("seed", seed); - const hdwallet = hdkey.fromMasterSeed(seed); - const wallet_hdpath = "m/44'/60'/0'/0/"; - const account_index = 0; - const fullPath = wallet_hdpath + account_index; - if (DEBUG) console.log("fullPath", fullPath); - const wallet = hdwallet.derivePath(fullPath).getWallet(); - const privateKey = "0x" + wallet._privKey.toString("hex"); - if (DEBUG) console.log("privateKey", privateKey); - const EthUtil = require("ethereumjs-util"); - const address = - "0x" + EthUtil.privateToAddress(wallet._privKey).toString("hex"); - - const qrcode = require("qrcode-terminal"); - qrcode.generate(address); - console.log("‍📬 Deployer Account is " + address); - for (const n in config.networks) { - // console.log(config.networks[n],n) - try { - const provider = new ethers.providers.JsonRpcProvider( - config.networks[n].url - ); - const balance = await provider.getBalance(address); - console.log(" -- " + n + " -- -- -- 📡 "); - console.log(" balance: " + ethers.utils.formatEther(balance)); - console.log( - " nonce: " + (await provider.getTransactionCount(address)) - ); - } catch (e) { - if (DEBUG) { - console.log(e); - } - } - } - } catch (err) { - console.log(`--- Looks like there is no mnemonic file created yet.`); - console.log( - `--- Please run ${chalk.greenBright("yarn generate")} to create one` - ); - } - } + "account", + "Get balance informations for the deployment account.", + async (_, { ethers }) => { + const hdkey = require("ethereumjs-wallet/hdkey"); + const bip39 = require("bip39"); + try { + const mnemonic = fs.readFileSync("./mnemonic.txt").toString().trim(); + if (DEBUG) console.log("mnemonic", mnemonic); + const seed = await bip39.mnemonicToSeed(mnemonic); + if (DEBUG) console.log("seed", seed); + const hdwallet = hdkey.fromMasterSeed(seed); + const wallet_hdpath = "m/44'/60'/0'/0/"; + const account_index = 0; + const fullPath = wallet_hdpath + account_index; + if (DEBUG) console.log("fullPath", fullPath); + const wallet = hdwallet.derivePath(fullPath).getWallet(); + const privateKey = "0x" + wallet._privKey.toString("hex"); + if (DEBUG) console.log("privateKey", privateKey); + const EthUtil = require("ethereumjs-util"); + const address = + "0x" + EthUtil.privateToAddress(wallet._privKey).toString("hex"); + + const qrcode = require("qrcode-terminal"); + qrcode.generate(address); + console.log("‍📬 Deployer Account is " + address); + for (const n in config.networks) { + // console.log(config.networks[n],n) + try { + const provider = new ethers.providers.JsonRpcProvider( + config.networks[n].url + ); + const balance = await provider.getBalance(address); + console.log(" -- " + n + " -- -- -- 📡 "); + console.log(" balance: " + ethers.utils.formatEther(balance)); + console.log( + " nonce: " + (await provider.getTransactionCount(address)) + ); + } catch (e) { + if (DEBUG) { + console.log(e); + } + } + } + } catch (err) { + console.log(`--- Looks like there is no mnemonic file created yet.`); + console.log( + `--- Please run ${chalk.greenBright("yarn generate")} to create one` + ); + } + } ); async function addr(ethers, addr) { - if (isAddress(addr)) { - return getAddress(addr); - } - const accounts = await ethers.provider.listAccounts(); - if (accounts[addr] !== undefined) { - return accounts[addr]; - } - throw `Could not normalize address: ${addr}`; + if (isAddress(addr)) { + return getAddress(addr); + } + const accounts = await ethers.provider.listAccounts(); + if (accounts[addr] !== undefined) { + return accounts[addr]; + } + throw `Could not normalize address: ${addr}`; } task("accounts", "Prints the list of accounts", async (_, { ethers }) => { - const accounts = await ethers.provider.listAccounts(); - accounts.forEach((account) => console.log(account)); + const accounts = await ethers.provider.listAccounts(); + accounts.forEach((account) => console.log(account)); }); task("blockNumber", "Prints the block number", async (_, { ethers }) => { - const blockNumber = await ethers.provider.getBlockNumber(); - console.log(blockNumber); + const blockNumber = await ethers.provider.getBlockNumber(); + console.log(blockNumber); }); task("balance", "Prints an account's balance") - .addPositionalParam("account", "The account's address") - .setAction(async (taskArgs, { ethers }) => { - const balance = await ethers.provider.getBalance( - await addr(ethers, taskArgs.account) - ); - console.log(formatUnits(balance, "ether"), "ETH"); - }); + .addPositionalParam("account", "The account's address") + .setAction(async (taskArgs, { ethers }) => { + const balance = await ethers.provider.getBalance( + await addr(ethers, taskArgs.account) + ); + console.log(formatUnits(balance, "ether"), "ETH"); + }); function send(signer, txparams) { - return signer.sendTransaction(txparams, (error, transactionHash) => { - if (error) { - debug(`Error: ${error}`); - } - debug(`transactionHash: ${transactionHash}`); - // checkForReceipt(2, params, transactionHash, resolve) - }); + return signer.sendTransaction(txparams, (error, transactionHash) => { + if (error) { + debug(`Error: ${error}`); + } + debug(`transactionHash: ${transactionHash}`); + // checkForReceipt(2, params, transactionHash, resolve) + }); } task("send", "Send ETH") - .addParam("from", "From address or account index") - .addOptionalParam("to", "To address or account index") - .addOptionalParam("amount", "Amount to send in ether") - .addOptionalParam("data", "Data included in transaction") - .addOptionalParam("gasPrice", "Price you are willing to pay in gwei") - .addOptionalParam("gasLimit", "Limit of how much gas to spend") - - .setAction(async (taskArgs, { network, ethers }) => { - const from = await addr(ethers, taskArgs.from); - debug(`Normalized from address: ${from}`); - const fromSigner = await ethers.provider.getSigner(from); - - let to; - if (taskArgs.to) { - to = await addr(ethers, taskArgs.to); - debug(`Normalized to address: ${to}`); - } - - const txRequest = { - from: await fromSigner.getAddress(), - to, - value: parseUnits( - taskArgs.amount ? taskArgs.amount : "0", - "ether" - ).toHexString(), - nonce: await fromSigner.getTransactionCount(), - gasPrice: parseUnits( - taskArgs.gasPrice ? taskArgs.gasPrice : "1.001", - "gwei" - ).toHexString(), - gasLimit: taskArgs.gasLimit ? taskArgs.gasLimit : 24000, - chainId: network.config.chainId, - }; - - if (taskArgs.data !== undefined) { - txRequest.data = taskArgs.data; - debug(`Adding data to payload: ${txRequest.data}`); - } - debug(txRequest.gasPrice / 1000000000 + " gwei"); - debug(JSON.stringify(txRequest, null, 2)); - - return send(fromSigner, txRequest); - }); + .addParam("from", "From address or account index") + .addOptionalParam("to", "To address or account index") + .addOptionalParam("amount", "Amount to send in ether") + .addOptionalParam("data", "Data included in transaction") + .addOptionalParam("gasPrice", "Price you are willing to pay in gwei") + .addOptionalParam("gasLimit", "Limit of how much gas to spend") + + .setAction(async (taskArgs, { network, ethers }) => { + const from = await addr(ethers, taskArgs.from); + debug(`Normalized from address: ${from}`); + const fromSigner = await ethers.provider.getSigner(from); + + let to; + if (taskArgs.to) { + to = await addr(ethers, taskArgs.to); + debug(`Normalized to address: ${to}`); + } + + const txRequest = { + from: await fromSigner.getAddress(), + to, + value: parseUnits( + taskArgs.amount ? taskArgs.amount : "0", + "ether" + ).toHexString(), + nonce: await fromSigner.getTransactionCount(), + gasPrice: parseUnits( + taskArgs.gasPrice ? taskArgs.gasPrice : "1.001", + "gwei" + ).toHexString(), + gasLimit: taskArgs.gasLimit ? taskArgs.gasLimit : 24000, + chainId: network.config.chainId + }; + + if (taskArgs.data !== undefined) { + txRequest.data = taskArgs.data; + debug(`Adding data to payload: ${txRequest.data}`); + } + debug(txRequest.gasPrice / 1000000000 + " gwei"); + debug(JSON.stringify(txRequest, null, 2)); + + return send(fromSigner, txRequest); + }); diff --git a/packages/hardhat/yhardhat.config.js b/packages/hardhat/yhardhat.config.js new file mode 100644 index 0000000..ab28de9 --- /dev/null +++ b/packages/hardhat/yhardhat.config.js @@ -0,0 +1,23 @@ +const { infuraRinkeby, rinkebyKey } = require('./access_keys'); + +require('@nomiclabs/hardhat-waffle'); + +// // Go to https://www.alchemyapi.io, sign up, create +// // a new App in its dashboard, and replace "KEY" with its key +// const ALCHEMY_API_KEY = "KEY"; + +// // Replace this private key with your Goerli account private key +// // To export your private key from Metamask, open Metamask and +// // go to Account Details > Export Private Key +// // Be aware of NEVER putting real Ether into testing accounts +// const GOERLI_PRIVATE_KEY = "YOUR GOERLI PRIVATE KEY"; + +module.exports = { + solidity: '0.8.0', + networks: { + rinkeby: { + url: infuraRinkeby, + accounts: [rinkebyKey], + }, + }, +}; diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index b181ac9..07bb645 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -53,7 +53,7 @@ const { ethers } = require("ethers"); */ /// 📡 What chain are your contracts deployed to? -const initialNetwork = NETWORKS.localhost; // <------- select your target frontend network (localhost, rinkeby, xdai, mainnet) +const initialNetwork = NETWORKS.rinkeby; // <------- select your target frontend network (localhost, rinkeby, xdai, mainnet) // 😬 Sorry for all the console logging const DEBUG = true; diff --git a/packages/subgraph/subgraph.yaml b/packages/subgraph/subgraph.yaml index 1d950d5..8f2eadb 100644 --- a/packages/subgraph/subgraph.yaml +++ b/packages/subgraph/subgraph.yaml @@ -4,21 +4,22 @@ schema: dataSources: - kind: ethereum/contract name: WayPoint - network: localhost + network: rinkeby source: - address: "0x5FbDB2315678afecb367f032d93F642f64180aa3" + address: "0x8f181e382dF37f4DAB729c1868D0A190A929D614" abi: WayPoint - startBlock: 1 + startBlock: 11000000 mapping: kind: ethereum/events apiVersion: 0.0.4 language: wasm/assemblyscript entities: - - Purpose - - Sender + - MetaNomad + - Space + - Portal abis: - name: WayPoint - file: ./abis/localhost_WayPoint.json + file: ./abis/rinkeby_WayPoint.json eventHandlers: # - event: SetPurpose(address,string) # handler: handleSetPurpose