Created
January 21, 2021 09:06
-
-
Save riordant/45b5e7e89c677064a4e5af7750ae7005 to your computer and use it in GitHub Desktop.
Miner for ganache-cli. run ganache-cli -d and this will mine blocks at an average of 5 seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ethers = require('ethers'); | |
// ganache deterministic mnemonic | |
const mnemonic = 'myth like bonus scare over problem client lizard pioneer submit female collect'; | |
// use last funded account | |
const account = "m/44'/60'/0'/0/9"; | |
// default ganache provider | |
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); | |
function getRandomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive | |
} | |
function timeout(secs) { | |
return new Promise(resolve => setTimeout(resolve, secs * 1000)); | |
} | |
async function mine() { | |
wallet = new ethers.Wallet.fromMnemonic(mnemonic, account); | |
wallet = wallet.connect(provider); | |
amount = "1"; | |
nonce = 0; | |
while(true){ | |
console.log('mining tx..'); | |
const transaction = { | |
nonce: nonce++, | |
to: wallet.address, | |
value: ethers.utils.parseEther(amount), | |
}; | |
await wallet.sendTransaction(transaction); | |
console.log('done.'); | |
await timeout(getRandomInt(2,8)); // average 5 second block time | |
} | |
} | |
mine(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment