Use this template to get started with Vyper smart contract development using ApeWorX framework.
You probably want to run this tutorial if
- You like Python
- You like smart contracts
- You love EVM-blockhains
The example covers
- Installing tools
- Compiling contracts
- Running unit tests
- Github Actions-based continuous integration integration
- Python 3.10 installation
- Poetry installed on Python
- We recommend working in Visual Studio Code with Vyper syntax highlighting plugin
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?
This will compile the contracts using the Vyper plugin for Ape.
ape compile
This will run the pytest-based test suite after recompiling the contracts:
ape test
More verbose:
ape test --log-cli-level=info
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
# TODO
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.