Posts

Showing posts with the label Brownie

Lottery Project Compiling: A Complete Tutorial

Image
In this tutorial, We are going to finally compile the lottery project . After making sure that it has been successfully compiled, we will run all the written tests to make sure everything works correctly in the contract. In the end, we will deploy the Decentralized Application on the Rinkeby test network. To be able to interact with the deployed contract, we will get some test Link tokens from Rinkeby Faucet. Compiling the Lottery Project Dapp In this part, we are going to finally compile, run and test our Lottery Dapp. Coppied to clipboard. brownie compile The result should be: Coppied to clipboard. Brownie v1.18.1 - Python development framework for Ethereum 1.33MiB [00:03, 402kiB/s] New compatible solc version available: 0.7.0 Compiling contracts... Solc version: 0.7.0 Optimizer: Enabled Runs: 200 EVM Version: Istanbul WARNING: Unable to compile OpenZeppelin/openzeppelin-contracts@3.4.0 due to a CompilerError - you ma...

Lottery Project Using Brownie: A Full Scale Dapp

Image
In this article, we are going to get started with the lottery project using Brownie. The main purpose of a lottery project in every network is to check the reliability of the randomness and use it for different purposes such as the lottery itself. In the lottery project, we are going to create a decentralized application using Brownie . In the end, we will be able to run the smart contract via Etherscan. Using Brownie for Lottery Project In this tutorial, we are going to first write a smart contract related to a lottery and write scripts related to testing and deploying the smart contract. We also want to make it a full-scale decentralized application, meaning that it is going to be an end-to-end Dapp with easy to use user experience. Every lottery needs a random variable. As randomness is a very complicated concept when it is going to be applied on the internet and here we are going to run it via the blockchain, it must be protected from hacks and cheating. What makes random...

Using Brownie to Switch between Different Networks

Image
In this article, we are going to switch between the different available networks we can connect to, using Brownie. Then, we'll write a statement in the Deploy.py to connect to the network requested in the terminal by the user (the developer). This kind of script for network management makes it easy for us to connect to any network that we want at any time it is required for testing and other purposes. How to Switch between Networks As you know, we have different networks to work with. We have already used some of them for deploying our contracts . Sometimes we need to write our deploy.py file in a way that we can switch between different networks and accounts and the deploy.py must understand which ones are available. Switch between Different Networks Before we get started with this task, we can check the keywords when we want to connect to different accounts. To look up the keyword related to any network, we write: Coppied to clipboard. brownie ...

Testing Deploy.py Script Using Brownie: A Full Analysis

Image
In this post, we will complete testing our deploy.py script using Brownie in more detail so that we can see if there is any problem at all. And if there is, we can analyze it in more detail. This kind of detailed test and code analysis becomes handy, especially when the code is too long and complex that we cannot so easily understand where the unexpected result originates from. Detailed Testing Deploy.py Using Brownie For more detailed testing, we can write in the terminal: Coppied to clipboard. brownie test -k Which in our case will be: Coppied to clipboard. brownie test -k test_updating_storage And the result will be: Coppied to clipboard. Brownie v1.18.1 - Python development framework for Ethereum ===================================================== test session starts ===================================================== platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 rootdir: /hom...

How to Interact with Smart Contracts Using Brownie

Image
After installing and working with Ganache CLI , we are going to interact with simple storage smart contracts Using Brownie. Meaning that we want to store and retrieve a value within the contract. After doing this you will see how simple and efficient Brownie is compared to other methods in python. We are also going to use testing modules to test the functionality of the contract and its deployment. Using Brownie to Interact with Smart Contracts In the previous section of this tutorial, we learned how to deploy our simple storage smart contract . In this one, we are going to interact with it, meaning that we want to store a value inside the contract and retrieve it using Brownie. After doing this you will see how simply and efficiently Using Brownie to interact with smart contracts can get compared to other methods in python. Retrieving the Stored Data: So, to follow our deploy.py script, we have: from Brownie import accounts, config, SimpleStorage def dep...

Using Ganache CLI with Brownie to Deploy A Smart Contract

Image
In this article, after installing Brownie , we are going to install the Ganache CLI (Command Line Interface) and use it with Brownie. The Ganache CLI is the same as Ganache IDE with the difference that it automatically runs without the need to open the Ganache IDE. At the end end of this tutorial, we will be able to deploy our smart contracts on top of Ganache CLI simulated blockchain. Installing Ganache: To continue our journey with Brownie, we need to make sure Ganache CLI has been installed successfully. To make sure that it has, and also see its virtual accounts, in your console (terminal) write: Coppied to clipboard. ganache And it should give you the test accounts like this: ganache v7.0.3 (@ganache/cli: 0.1.4, @ganache/core: 0.1.4) Starting RPC server Available Accounts ================== (0) 0x960F41C52ffAef71fFef2fFBC3C0EA5Dc5748086 (1000 ETH) (1) 0x39Cf64532C1126c6C9Fa0a02338389d1eb861A12 (1000 ETH) (2) 0xA1E47c46425e2456566...