I had been watching a course online, where I learnt that we can compile & deploy any smart contract to blockchain and then with web3.js we can interact with the smart contract. So why do we need something like truffle or hardhat when we can actually build anything such as a Dapp? Please tell the advantages?
I had used both Truffle, Brownie && Hardhat for SmartContract development. All of them are good, and they serve their purpose.
The reason you need these tools comes down to the fact that Blockchain development is very specific.
1. You need a running blockchain to which you can
2. You also need a way to manage your
blockchain networks(to decide where you want to deploy your contracts)
3. You want to estimate the
cost/gasof your function easily
4. In some tests, you might want to jump ahead in time on blockchain. (To test function that locks up funds for a year or something like that)
5. There are likey hundreds more of specific cases for which regular development tools would not be of much use because they were not made for a blockchain development
Hardhat all have an
inbuilt functionality that is ready for your use out of the box.
Which one to use is up to you.
2. Brownie is Python based (You write tests and deployment scripts in Python instead of JS)
3. Hardhat is also JS based, but you can write your tests and scripts in TypeScript too.
However, as someone who had used (and is still using) all three of those extensively. I would go for a Hardhat (and I say that even though I love Brownie). But in my experience, the Hardhat is the most forgiving to newcomers. Plus, it has amazing libraries that make your life easier.
(This was just an example to showcase it here). But you can clearly see how the
OrganizationManager contract has
We also see its cost in terms of gas, + the deployment cost of the Contract itself. A rather helpful feature for any blockchain developer.
Assuming the last line of your question is "when we can't actually build anything such as a Dapp"
So, in Blockchain development, testing on real environments can be costly. Since you mentioned smart contracts, you must be referring to Solidity. Now, on Ethereum Blockchain, performing any transaction or even deploying your contract requires gas. So, in cases where you don't know whether your smart contract is truly working well. It is stupid to post you code on the main blockchain as it cannot be erased, will take up space on the main chain and will also cost you money.
Hardhat and Truffle allow us to go beyond these limitations.
Do let me know if you have further questions. We both could also explore and learn together