Ethereum + Python = براوني

تحية عزيزي عشاق التشفير!



سنتحدث اليوم عن براوني - وهو تناظري لإطار Truffle ، والذي يُستخدم غالبًا لتطوير عقود ذكية من أجل Solidity واختبارها ونشرها (والتي يمكنك قراءتها في سلسلة من المقالات ذات الصلة هنا ).



فلماذا نحن بحاجة إلى إطار آخر ، وما هو الفرق الرئيسي عن Truffle؟



  • أولاً ، يستخدمون لغات مختلفة - بينما يعتمد Truffle على JS ، لا يعرف الجميع هذه اللغة ولا يشعر الجميع بالراحة في استخدامها ؛ يستخدم البراوني بيثون 3.
  • ثانيًا ، نظرًا لتكامل البرامج المختلفة ، فإن البراوني يجعل التطوير أكثر ملاءمة: هنا مدير حزم ethpm للعقود الذكية ، و ganache لنشر سلسلة اختبار محلية ، والاختبارات من خلال pytest ، وجميع إصدارات مترجمين solc ، وحتى الارتباطات بـ MythX - أداة ل البحث التلقائي عن الأخطاء في العقود الذكية - وبعبارة أخرى ، يقدم البراوني أدوات لدورة التطوير بأكملها. بالطبع يتيح لك Truffle أيضًا استخدام جميع هذه الأدوات ، ولكنها ليست مدمجة في الإطار ويجب تثبيتها بشكل إضافي.
  • ثالثًا ، يسمح لك البراوني بالعمل ليس فقط مع العقود الذكية على Solidity ، ولكن أيضًا على vyper - وهو عبارة عن مستند مستوحى من الثعبان لتطوير العقود الذكية.


وبالتالي ، إذا كنت تفضل العمل مع Python وتريد أن تجعل من السهل عليك تطوير عقود ذكية ، فإن الكعكة تستحق التجربة بالتأكيد.



ماذا يمكن أن يفعل البراوني؟

كما هو مذكور في المستودع نفسه ، فإن البراوني هو إطار تطوير عقد ذكي كامل الدورة للمنصات القائمة على Ethereum التي تدعم:



  • العديد من لغات برمجة العقود الذكية: Solidity و Vyper.
  • عقود البناء.
  • تفاعل تفاعلي مع العقود.
  • اختبار العقود الذكية مع pytest.
  • مخطوطات للتفاعل مع العقود الذكية.
  • العمل مع قوالب العقود الذكية.


brownie , brownie . pip:



pip install eth-brownie



brownie .



help brownie
brownie --help
Brownie v1.6.9 - Python development framework for Ethereum

Usage:  brownie <command> [<args>...] [options <args>]

Commands:
  init               Initialize a new brownie project
  bake               Initialize from a brownie-mix template
  ethpm              Commands related to the ethPM package manager
  compile            Compiles the contract source files
  console            Load the console
  test               Run test cases in the tests/ folder
  run                Run a script in the scripts/ folder
  accounts           Manage local accounts
  gui                Load the GUI to view opcodes and test coverage
  analyze            Find security vulnerabilities using the MythX API

Options:
  --help -h          Display this message

Type 'brownie <command> --help' for specific options and more information about
each command.


brownie



brownie brownie-config.yaml. brownie init



init
brownie init salut_habr
Brownie v1.6.9 - Python development framework for Ethereum

SUCCESS: Brownie environment has been initiated at salut_habr


brownie bake template_name



brownie bake token
Brownie v1.6.9 - Python development framework for Ethereum

Downloading from https://github.com/brownie-mix/token-mix/archive/master.zip...
5.62kiB [00:00, 2.82MiB/s]
SUCCESS: Brownie mix 'token' has been initiated at token


ERC-20 ( token).

:



├───build #   ,      .
│   ├───contracts #    ,  ABI  .
│   └───deployments #         .
├───contracts #   (  ).
├───interfaces #   .
├───reports #  .
├───scripts # Python           run.
└───tests #    pytest   .


, brownie , brownie-config.yaml — , .



brownie



brownie , , : compile, console, test run.



brownie compile



, contracts . , , "_",- brownie ( ).



./build/contracts/ json-, ABI , - -.



brownie , , . , -all.



brownie compile --all
Brownie v1.6.9 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.5.17+commit.d19bba13.Windows.msvc
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
 - Token...
 - SafeMath...

Brownie project has been compiled at C:\Users\Default\Documents\token\build\contracts


, , brownie-config.yaml



brownie test



pytest, , , CI/CD.



brownie test
Brownie v1.6.9 - Python development framework for Ethereum

==================================================================================================== test session starts =====================================================================================================
platform win32 -- Python 3.8.3, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\Default\Documents\token
plugins: eth-brownie-1.6.9, hypothesis-5.5.4, forked-1.1.3, xdist-1.31.0, web3-5.5.1
collecting ... Launching 'ganache-cli.cmd --port 8545 --gasLimit 6721975 --accounts 10 --hardfork istanbul --mnemonic brownie'...
collected 7 items

tests\test_approve_transferFrom.py ......                                                                                                                                                                               [ 85%]
tests\test_transfer.py .                                                                                                                                                                                                [100%]

===================================================================================================== 7 passed in 9.35s ====================================================================================================== 
Terminating local RPC client...


tests/



brownie run



scripts. brownie 2.x, CI/CD ( ).



brownie run
brownie run token
Brownie v1.6.9 - Python development framework for Ethereum

TokenProject is the active project.
Launching 'ganache-cli.cmd --port 8545 --gasLimit 6721975 --accounts 10 --hardfork istanbul --mnemonic brownie'...

Running 'scripts.token.main'...
Transaction sent: 0xe36fbf7d93c1c91bde5e9290128999ed06ea54eb68352fb477fa91ce8072f472
  Gas price: 0.0 gwei   Gas limit: 549953
  Token.constructor confirmed - Block: 1   Gas used: 549953 (100.00%)
  Token deployed at: 0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87

Terminating local RPC client...


brownie console



brownie: , . :



brownie console
Brownie v1.6.9 - Python development framework for Ethereum

TokenProject is the active project.
Launching 'ganache-cli.cmd --port 8545 --gasLimit 6721975 --accounts 10 --hardfork istanbul --mnemonic brownie'...
Brownie environment is ready.
>>> dir()
[Fixed, Gui, SafeMath, Token, Wei, a, accounts, alert, compile_source, config, dir, history, network, project, rpc, run, web3]


brownie, , web3py.



/



brownie ganache ( Ethereum) , ( Quorum!). --network network_name console run, network_name brownie-config.yaml. ETH ETC, . , yaml . develop, test master ( ), Azure .



تلخيص ، يمكننا القول أن الكعكة هي بالفعل حل جاهز إلى حد ما جاهز للتطوير لـ Ethereum وقادر على تلبية جميع الاحتياجات الناشئة تقريبًا في عمليته. Pythonists وليس فقط يجب بالتأكيد محاولة جعل مشروعهم المقبل على ذلك.




All Articles