How to Compile the smart contract
In this
tutorial we are going to use brownie for compiling smart contract
What you will learn:
- What is Solidity
- What is brownie
- What is Ganache
- How to connect brownie with ganache-cli using cmd
Solidity is an object-oriented, high-level language it is similar to java so if you have a background in java it will make your life more easier to learn it.
Smart contracts are programs which govern the behavior of accounts within Ethereum state. There are other smart contract languages, such as Vyper even though Vyper is more secure than solidity but solidity must well known than others.
Let us begin with the basic example:
Open Visual Studio Code and install solidity extension, afterward name the file of the smart contract which take the extension of (.sol)
HelloWorld.sol
there's many tools out there for compiling smart contract such as (Remix IDE , Brownie , HardHat) but in this tutorial we are going to use brownie.
Brownie is a Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine(EVM), and is full support by solidity and Vyper; for more information about brownie go to this link here.
Requirements Tools
- Python 3.9 or later (to install brownie)
- Node js (to install ganache-cli)
- Ganache-Cli (Ethereum Network)
you can use the following command to check that TK has been correctly installed:
now if all dependencies has installed in your system, let's initialize it by creating a new folder and type:
if it doesn't work try this :
Now you should see the following structure:
- build/: Project data
- contracts/: Contract sources
- interface/: Interface sources
- reports/: JSON report files for use in the GUI
- scripts/: Scripts for deployment and interaction
- tests/: Scripts for testing the project
Now paste the smart contract file in the contracts folder and open the CMD in the same directory
To see our brownie network list type this:
you may consider that ganache doesn't exits in the list , so let's add it by :
open another CMD and type :
Let's add Ganach-Cli by typing this in the brownie console:
now if you check brownie networks list you should see ganache-cli exits on the list.
afterward, let's connect it with brownie by typing this :
the
console is useful when you want to interact directly with contracts
deployed on a non-local chain, or quick testing as you develop.
let's see ganache accounts
if you see an empty brackets [], just instead of typing brownie console --network ganache-gui , try typing
>> accounts
>> type accounts
Cool
ReplyDelete