What is the difference between this two? I understand that Ganache is like a
fake blockchain, but Truffle has that too ?
What are the limitations of each and under which circumstance we use either of them ?
Ganache allows you to create a private Ethereum blockchain for you to run tests, execute commands, and inspect state while controlling how the chain operates. It gives you the ability to perform all actions you would on the main chain without the cost. Many developers use this to test their smart contracts during development. It provides convenient tools such as advanced mining controls and a built-in block explorer.
Truffle is a developer environment, testing framework and asset pipeline for blockchains. It allows developers to spin up smart contract project at the click of a button and provides you with a project structure, files, and directories that make deployment and testing much easier (or else you would have to configure these yourself).
under which circumstance we use either of them
As a developer, you would spin up a Truffle (
truffle init) project that lays out the structure of your project. Once you start coding a little bit, you will want to test the code, but need a blockchain to do so. Now you run Ganache to be this blockchain. In your deployment file (a file that Truffle gives you when you create a project), you can point your project to either use Ganache or to use the main network. You can then run
truffle migrate (which automatically runs
truffle compile for you), to deploy the contracts with the data you provided in the migration files.
What are the limitations of each
Truffle isn't really limited in that all it is doing is providing a framework for you to sculpt a project in. The only "limitation" would simply be the features they may not have added yet.
Ganache is a little different, in that it is attempting to mimic the main network. There are a few problems here:
There are no miners on Ganache. Because of this, you cannot accurately mimic miner actions on the main network. As an example, say you wanted to send a transaction that filled almost all of the block. You can set the block height to 7M on Ganache and send a 6.9M transaction no problem. On the main network (depending on the current throughput), this transaction may or may not ever get mined.
gasLimit on the main network is a moving target (it can be changed by miners. If, for some reason, you are depending on an exact number (as you can set in Ganache), you may find that you will run into issues.
Truffle is a development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier. With Truffle, you get: Built-in smart contract compilation, linking, deployment and binary management.
Ganache is an ethereum client which one can use for Ethereum development.
Ganache is part of Truffle ecosystem. You can use ganache for the development of DAPP and once it is developed and tested on the ganache you can deploy your DAPP on ethereum client like geth or parity.
Truffle will enable you to develop, test and deploy your DAPP.
As you note, Truffle indeed bundles its own test blockchain; you can use the Ganache app with Truffle if you want (https://truffleframework.com/docs/truffle/quickstart#alternative-migrating-with-ganache), but it’s easier to use the built-in one, even easier than the existing QuickStart makes it seem. (See my suggested QuickerStart for how easy this is.) One gotcha, for debugging a test execution with the built-in blockchain: run
truffle develop --log in a separate terminal session to get the relevant hashes you will need for debugging.