mkdir test
cd test
2. Set up pyenv
- Linux
sudo apt update -y
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
exec "$SHELL"
pyenv install 3.11.8
pyenv global 3.11.8 # If you only want to set the local Python version, you can invoke `pyenv local 3.11.8` instead.
python -m venv venv
source venv/bin/activate # If you use Windows, you can active the virtual environment by invoking `venv\Scripts\Activate.ps1` instead.
pip install git+https://github.com/vyperlang/vyper.git@master
pip install git+https://github.com/pcaversaccio/snekmate.git@modules
vi Test.vy
Paste the following snippet into Test.vy
:
# pragma version ~=0.4.0b5
from snekmate.utils import ECDSA
@external
@pure
def recover_sig(hash: bytes32, signature: Bytes[65]) -> address:
assert len(signature) == 65, "ECDSA: only 65-byte signatures supported"
r: uint256 = extract32(signature, empty(uint256), output_type=uint256)
s: uint256 = extract32(signature, 32, output_type=uint256)
v: uint256 = convert(slice(signature, 64, 1), uint256)
return ECDSA._try_recover_vrs(hash, v, r, s)
Important
You can import all π snekmate logic via the namespace snekmate
, i.e. snekmate.auth
, snekmate.tokens
etc.
vyper Test.vy
This will output:
0x6102e9610011610000396102e9610000f35f3560e01c6325d869828118610194576064361034176102e55760243560040160418135116102e5576020813501808261018037505060416101805118156100cb576028610200527f45434453413a206f6e6c792036352d62797465207369676e6174757265732073610220527f7570706f727465640000000000000000000000000000000000000000000000006102405261020050610200518061022001601f825f031636823750506308c379a06101c05260206101e052601f19601f6102005101166044016101dcfd5b6101807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602082510313600116156102e5575f60051c60051b602001810151905061020052610180601f602082510313600116156102e557602060051c60051b602001810151905061022052610180516041116102e5576101e051610280526001610260526102606020810151815160200360031b1c905061024052602060043560405261024051606052610200516080526102205160a05261018f610260610198565b610260f35b5f5ffd5b7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a060a051111561024357602260c0527f45434453413a20696e76616c6964207369676e6174757265206073602076616c60e0527f75650000000000000000000000000000000000000000000000000000000000006101005260c05060c0518060e001601f825f031636823750506308c379a0608052602060a052601f19601f60c0510116604401609cfd5b5f6101605260405160e052606051610100526080516101205260a051610140526020610160608060e060015afa506101605160c05260c0516102dd57601860e0527f45434453413a20696e76616c6964207369676e617475726500000000000000006101005260e05060e0518061010001601f825f031636823750506308c379a060a052602060c052601f19601f60e051011660440160bcfd5b60c051815250565b5f80fd841902e98000a16576797065728300030b0013
π Congratulations, you just compiled a Vyper contract using modules!
π€