Skip to content

Hello World project for Vyper smart contract programming using ApeWorX framework

Notifications You must be signed in to change notification settings

tradingstrategy-ai/vyper-ape-hello-world

Repository files navigation

Vyper and ApeWorX Hello World Project

Automated test suite

Use this template to get started with Vyper smart contract development using ApeWorX framework.

You probably want to run this tutorial if

The example covers

Prerequisites

Installation

First, clone this project:

git clone https://github.com/tradingstrategy-ai/vyper-ape-hello-world.git

Then install ape and all Python packages using Poetry:

cd project
poetry shell
poetry install
ape plugins install vyper  # TODO: How to get rid of this step and automate it?

Usage

Compile the contracts

This will compile the contracts using the Vyper plugin for Ape.

ape compile

Run unit tests

This will run the pytest-based test suite after recompiling the contracts:

ape test

More verbose:

ape test --log-cli-level=info

Adding breakpoints to tests

So there is a bug and you want to debug it in Python... The easiest way is with ipdb console debugger based on Jupyter.

Edit test.py and drop in the breakpoint (you might want to add this as Visual Studio Code Snippet):

def test_hello_world(hello_world_contract):
    """We receive Hello World from the deployed contract accessor method"""
    import ipdb ; ipdb.set_trace()
    assert hello_world_contract.helloWorld() == "Hello Vyper!"

And run tests without stdin enabled:

ape test -s

You get interrupted at the breakpoint:

tests/test_hello_world.py::test_hello_world SUCCESS: Contract 'HelloWorld' deployed to: 0x274b028b03A250cA03644E6c578D81f019eE1323
> /Users/moo/code/ts/ape-vyper-hello-world/tests/test_hello_world.py(27)test_hello_world()
     25     """We receive Hello World from the deployed contract accessor method"""
     26     import ipdb ; ipdb.set_trace()
---> 27     assert hello_world_contract.helloWorld() == "Hello Vyper!"

ipdb> 

Now you can poke around:

ipdb> type(hello_world_contract)
<class 'ape.contracts.base.ContractInstance'>

Or drop to ipython (gives better command line editor for typing Python):

ipdb> interact
*interactive*
In [1]: dir(hello_world_contract)
Out[1]: 
['address',
 'balance',
 'call_view_method',
 'code',
 'codesize',
 'contract_type',
 'decode_input',
 'get_event_by_signature',
 'helloWorld',
 'invoke_transaction',
 'is_contract',
 'nonce',
 'provider',
 'receipt',
 'txn_hash']

In [5]: hello_world_contract.balance
Out[5]: 0

Deploy

# TODO

Learn more

Brought you by Trading Strategy. For any questions and follow-ups:

Please kindly give heads up and contact via other channels before opening issues or pull requests.

About

Hello World project for Vyper smart contract programming using ApeWorX framework

Topics

Resources

Stars

Watchers

Forks