I am trying to deploy thousands of contracts on Ganache GUI. At first, it process all transactions very fast (deploy contracts and transactions for calling setters functions) . After some transactions, may 500/1000 or more, it become so slow and process a single transaction in 5-8 seconds or sometime even more . Is it normal ? It is because of calculating difficulty level , automatically ?….
[Ethereum] Ganache Processing becomes very slow (with Automining Option) after consecutive thousands transactions
ganachejavascriptnodejsweb3js
Related Solutions
This is what my working dir looks like:
PS C:\Projects\Eth_Dev\simple> ls
Directory: C:\Projects\Eth_Dev\simple
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 27/02/2019 21:25 contracts
d----- 27/02/2019 21:22 node_modules
d----- 27/02/2019 21:25 test
-a---- 27/02/2019 21:25 691 compile.js
-a---- 27/02/2019 21:29 907 deploy.js
-a---- 27/02/2019 21:22 152654 package-lock.json
-a---- 27/02/2019 21:28 339 package.json
The contents of package.json
:
{
"name": "myContract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.2.5",
"mocha": "^5.2.0",
"solc": "^0.4.25",
"truffle-hdwallet-provider": "0.0.3",
"web3": "^1.0.0-beta.35"
}
}
The only other command I had to run in addition to npm install
was npm install --global --production windows-build-tools
The contents of contracts\myContract.sol
pragma solidity ^0.4.17;
contract MyContract {
string public message;
function MyContract(string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
This is a deploy.js script that seems to work. Running 'node deploy.js' does the deploy to the Rinkeby network
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const {interface, bytecode} = require('./compile');
const provider = new HDWalletProvider(
'your twelve word mnemonic',
'https://rinkeby.infura.io/v3/YOUR_API_KEY'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account', accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data:bytecode, arguments:['This is deployed!']})
.send({gas:'1000000', from: accounts[0]});
console.log('Contract deployed to ', result.options.address);
};
deploy();
There is a reference to a compile file. The compile.js looks like this:
const path = require('path'); //builds a path from the current file.
const fs = require('fs');
//Need the solidity compiler
const solc = require('solc');
//__dirname will get the inbox dir path.
//look in the contracts folder and get a path to the Inbox.sol file.
const myContractPath = path.resolve(__dirname,'contracts','myContract.sol');
//Read in the contents of the file. The raw source code.
const source = fs.readFileSync(myContractPath,'utf8');
//console.log(solc.compile(source,1));
//This will export the compiled file. Make it available
//At the moment only interested in the Inbox contract.
module.exports = solc.compile(source,1).contracts[':MyContract'];
And the output:
PS C:\Projects\Eth_Dev\simple> node .\deploy.js
Attempting to deploy from account 0x15ec...B
Contract deployed to 0x5...2DA9269a
Best Answer
Try to work with ganache-cli instead of ganache-gui.
We faced similar issues with our integration tests - lots of transactions are very slow with the Ganache GUI (especially unter Windows the UI has update problems).
The command line interface ganache-cli is much more stable and runs in terminal as well as in docker container. From the functional point of view you have everything what you need in ganache-cli.
Ganache GUI is nice for demonstrations to management & customers or training sessions. During development and for test purposes it's better to use the ganache-cli.