Welcome back to Vyper for Beginners! This lesson will cover my recommended toolkit for writing, compiling, testing, and finally deploying a Vyper contract.
It’s no surprise that the most fully-featured toolkit for Vyper is written in Python. Brownie is, by their own description:
A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
For those familiar with the Ethereum development ecosystem, Brownie is the Python equivalent of Truffle (written in JavaScript). Both tools allow you to write, test, deploy and debug smart contracts.
Brownie has native support for both Vyper and Solidity contracts, so you don’t need to use a separate toolkit as you move between the languages.
Vyper for Beginners
- Part 1 — Introduction
- Part 2 — Toolkit
- Part 3 — Variables, Flow Control, Functions, Hello World!
- Part 4 — Interfaces
- Part 5 — Dynamic Arrays
Development Platform
I do all of my development using Linux, and all of my installation instructions here will be written with my primary workstation as the example. I am using Pop_OS (a Ubuntu derivative) version 21.10.
If you choose to use a different Linux distribution or a different operating system entirely, that is OK. Brownie and Vyper are cross-platform and will work on any system that offers a recent version of Python 3.
If you cannot dedicated a machine to Linux development, I recommend installing it in a virtual machine (VirtualBox or similar). The advantage to using a VM for development is that you can maintain a platform compatibility with this guide without affecting your primary workstation.
Providing a complete installation guide for multiple operating systems is beyond the scope of this lesson series, so if you decide to deviate from my recommendations please be aware that you may run into issues that I cannot solve.
I am using the following package versions:
- Python version 3.9.7
- Pip version 20.3.4 (installed via
apt
) - Brownie version 1.18.1
- Vyper version 0.3.2 (installed via
pip+git
, more on this later)
I do my development using VSCode version 1.65.2 and an assortment of helpful extensions:
- Pylance v2022.3.3
- Python IntelliSense v2022.2.1924087327
- Vyper v0.0.13
Formatting Conventions
Whenever I include monospace-formatted text
inside a normal paragraph, I am highlighting a command, variable, or some programming element relevant to the topic.
Whenever I show a block of text inside a code block, it signifies some program output or input that I want you to either enter on your machine or review from mine.
This is an example of a code block.
It may contain new lines and special characters, but it will be continuous from top to bottom.
I will include shell commands from a Linux / Mac / Windows terminal in a code block. Whenever you see a code block with any of these symbols, you can be reasonably assured that I’m showing you a shell command:
$
#
>>>
My local workstation is named hades
, and my user is named devil
so you will frequently see code blocks that look like this:
devil@hades:~$ some_commmand
This signifies that I’m pasting the actual input and output from a terminal. Yours may look different, and I expect that you’ll choose a different login and machine name (though I do love imitation, very flattering).
Installation
The first thing you will need is a functional Python installation, plus the development libraries needed to install the remainder of the tools via pip
(the Package Installer for Python).
Open a terminal and execute the following:
devil@hades:~$ sudo apt install python3 python3-dev python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
[...]
This will install the necessary base packages from apt
, then we can use pip
for the remainder.
devil@hades:~$ pip install eth-brownie
[...]
Installing collected packages: eth-brownie
Successfully installed eth-brownie-1.18.1
Now we install Vyper, except via a special command. Vyper 0.3.2 has not been released, but it is the first version to offer support for Dynamic Arrays. This is a feature we want, so until it has been officially packaged and released, we will install it via a special pip
option, which retrieves and compiles it from the most recent version available on GitHub.
devil@hades:~$ pip install git+https://github.com/vyperlang/vyper
Collecting git+https://github.com/vyperlang/vyper
Cloning https://github.com/vyperlang/vyper to /tmp/pip-req-build-py99gbr8
Running command git clone -q https://github.com/vyperlang/vyper /tmp/pip-req-build-py99gbr8
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing wheel metadata ... done
Requirement already satisfied: semantic-version==2.8.5 in ./.local/lib/python3.9/site-packages (from vyper==0.3.2+commit.5dcd8a78) (2.8.5)
Requirement already satisfied: asttokens==2.0.5 in ./.local/lib/python3.9/site-packages (from vyper==0.3.2+commit.5dcd8a78) (2.0.5)
Requirement already satisfied: pycryptodome<4,>=3.5.1 in ./.local/lib/python3.9/site-packages (from vyper==0.3.2+commit.5dcd8a78) (3.14.1)
Requirement already satisfied: wheel in /usr/lib/python3/dist-packages (from vyper==0.3.2+commit.5dcd8a78) (0.34.2)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from asttokens==2.0.5->vyper==0.3.2+commit.5dcd8a78) (1.16.0)
Building wheels for collected packages: vyper
Building wheel for vyper (PEP 517) ... done
Created wheel for vyper: filename=vyper-0.3.2+commit.5dcd8a78-py3-none-any.whl size=256175 sha256=2ec85e5554580d4f14ae523509b923bbb1f3b14346614797810037a015234b8a
Stored in directory: /tmp/pip-ephem-wheel-cache-vac30sqr/wheels/1f/6f/95/94488289c0848a7fe536f487b6b6ff1b3cafced9a34e5710d0
Successfully built vyper
Installing collected packages: vyper
Attempting uninstall: vyper
Found existing installation: vyper 0.3.1
Uninstalling vyper-0.3.1:
Successfully uninstalled vyper-0.3.1
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
eth-brownie 1.18.1 requires vyper==0.3.1, but you have vyper 0.3.2+commit.5dcd8a78 which is incompatible.
Successfully installed vyper-0.3.2+commit.5dcd8a78
Please do not be intimidated by all of this console output. Pip is telling us here that it built Vyper version 0.3.2 from the GitHub source (as of the commit tagged 5dcd8a78
), then detected an existing installation of 0.3.1, which is uninstalled and replaced with our 0.3.2 version. It offers a helpful warning that eth-brownie
requires an exact version of 0.3.1, but ours does not match.
This will be resolved in the future, so if you’re reading this after Vyper 0.3.2 has been released, simply ignore all of this.
A Simple Brownie Project
To create a directory for your Brownie project, create it using a file explorer or on the terminal using mkdir directory_name
. Then, inside the terminal, move into the directory and create the project structure using Brownie:
devil@hades:~$ mkdir vyper_for_beginners
devil@hades:~$ cd vyper_for_beginners/
devil@hades:~/vyper_for_beginners$ brownie init
Brownie v1.18.1 - Python development framework for Ethereum
SUCCESS: A new Brownie project has been initialized at /home/devil/vyper_for_beginners
Next Steps
In the next lesson I will cover the requirements for a Vyper smart contract, discuss the basic variable types that Vyper offers, compare the control and logic structures against Python, and demonstrate how to write, test, and deploy a very simple “Hello World” contract in Vyper.