Smart Contracting with Vyper and Ape

Hello, and welcome to another episode of… oh wait, wrong channel.

Lets start over then!

Tired of contract Solidity is SoVerbose, ICantTakeItAnymore, Etc { … } ? Yeah, me too. That’s why I decided to write EVM smart contracts with “the other” stack! LFG Vyper!

What’s Vyper? It’s a Pythonic Smart Contract Language for the EVM. def is_it_nicer_to_write() → bool: return True

It’s picking up attention thanks to some big DeFi projects (Hello Curve), and people looking beyond Solidity.

This post gives a brief overview of the ecosystem, and takes you from 0 to 100 faster than Usain Bolt.

(Brief) Ecosystem Comparison

So, how does this compare with the Solidity ecosystem? Here’s a very rough comparison table:

Note: these things are not very clean to categorize since the tools can do many things and/or span through different ecosystems.
Note: these things are not very clean to categorize since the tools can do many things and/or span through different ecosystems.

(Brief) Ecosystem Overview

Now let’s quickly go through the main tools, so you know what’s what:

  • Vyper: as mentioned, it’s how you write the smart contracts. That means you’re gonna have the docs open all the time. Here’s a nice intro to learn how to write Vyper: the definitive 0 to 1 guide.

  • Brownie: the OG development and testing framework, actually written in python (but supports Solidity contracts).

  • ApeWorx: a newer alternative for developing contracts. While the focus is mainly on Vyper contracts, it also supports Solidity. Here’s a nice intro to Ape.

  • Ganache: also an OG tool, for spinning up your own node, and testing locally. Ganache is also agnostic to how your contracts are written.

It’s also worth mentioning Titanoboa, since it’s under the Vyper team’s umbrella, which is a very new Vyper interpreter with a bunch of features!

Getting started quickly

Ok, here we go. Start by ensuring you got an up to date python --version installed (currently. anything >= 3.10 is new-ish).

  1. Create a virtual environment, and activate it

    python -m venv <my-project>

    cd <my-project>

    source bin/activate

  2. then install ape and vyper using pip
    pip install vyper eth-ape

  3. freeze the packages cause it’s a good practice
    pip freeze > requirements.txt

  4. run ape --version

If you get an output with something like 0.6.10, then great, you got ape running!

  1. Now it’s time to start the ape project: ape init

  2. Configure ape now, or later, up to you. If you do it now, you’ll want to familiarize with the docs

    1. Edit the ape-config.yaml with plugins, networks, etc.

    2. Then run ape plugins install . to install the plugins

  3. Now go and write some code

touch contracts/hello.vy

# and add this into hello.vy
@external
def hello() -> bool:
    return True

Then you can ape compile -s. Things will be successful if it outputs the deployment bytecode size.

Now you’re ready to learn the language and write Vyper contracts!

Once you’re done with the contracts, it’s time to test! Note: the Vyper docs talk about Brownie and Ethereum Tester, but I prefer using Ape - follow its docs.

Finally, time to run scripts to deploy things. Again, we use Ape for that.

You might want to deploy locally on a mainnet fork, I like using Foundry’s Anvil for that.

And that’s pretty much it, we’ve covered the basics to get started building with Vyper and Ape.

Other Resources

Many people have written about Vyper, and they did a better job than me. Check their stuff.

Need real time help? Join Vyper’s discord and Ape’s discord channels.

Subscribe to omnifient
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.