7

I know that the most used framework for smart contract that is used for testing, deployment etc is Truffle. But, since I am not very good at javascript (i am mainly coding in python)- I saw there is an option to use Brownie (or Populus).

How do these 2 frameworks differ, will there be any drawbacks if choosing Brownie over Truffle? Any differences at all?

Any recommendations?

1
  • 3
    There is also Buidler and Embark. If you like python probably you will feel more familiar with brownie, but you will have to use some node/javascript tools that do not have a python counterparte yet. Truffle used to be the most popular so you will find many articles and tutorials, but sometimes is not very flexible and many people hate it.
    – Ismael
    Oct 1 '20 at 17:30
8

If you are equally strong in Python and JavaScript, Brownie is a better choice, because Python as a programming language is more suited for tasks needed from a smart contract programming framework.

  • You can handle numbers, like uint256 and decimals, as numbers in Python whereas in JavaScript you need use strings or hacky classes. There are a lot of big numbers in smart contract development.

  • JavaScript forced async/await makes linear code, like a deployer, harder to follow and read, whereas in Python threaded model and optional async keeps simple scripts simple to debug

  • Python is natively optionally typed whereas in JavaScript you need to transpile to TypeScript, decreasing debuggability and bringing other issues as well

  • Pytest testing framework makes tests faster and easier to write and read. Tests are a crucial part of smart contract development and making testing easy is critical for security.

  • Python is the number one language in data science and finance, so there are many other synergies to financially related blockchain work.

  • JavaScript is used in-browser and all web frontends. If you need to learn programming languages from the scratch, in some point you need to write a frontend for your smart contract and JavaScript programming knowledge will become necessary.

An example comparing the readability of a single line of test code between Brownie and Truffle

assert(await staking.methods().currentlyStaked.call()).toNumber()).equal(STAKE_PRICE + STAKE_PRICE_2);

Would be in Python:

assert staking.currentlyStaked() == STAKE_PRICE + STAKE_PRICE_2

Also if you need to stick with JavaScript (you do not know Python) I suggest going to Hardhat instead of Truffle. Hardhat is a newer, more modern, JavaScript-based smart contract development framework and easier to work with than Truffle that carries a lot of legacy code.

3
  • 1
    In Brownie, could even be assert staking.currentlyStaked() == STAKE_PRICE + STAKE_PRICE_2 Jul 8 '21 at 9:59
  • Thank you, updated the answer Jul 8 '21 at 10:39
  • Javascript now has a built-in object to handle big numbers, BigInt (instead of hacky classes like bn.js). It's still a PITA to use, though...
    – Undead8
    Jul 9 '21 at 0:32
0

I haven't tried truffle yet, but I think Javascript should, at least, be more potent and more adequate to handle smartcontracts. the fact that javascript is oriented with async hooks and functions allows for you to wait for confirmation of things that have happened, making tests more robust than rather "waiting X seconds" and expect the network to have finished by then

2
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 17 '21 at 0:11
  • Python is also object oriented and has async hooks and functions. The number you pass into Brownie's TransactionReceipt.wait() is the number of confirmations to wait for, not the number of seconds to wait.
    – Josh Davis
    yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.