{"id":15407123,"url":"https://github.com/ltfschoen/vyper-test","last_synced_at":"2025-04-18T03:18:05.415Z","repository":{"id":50207708,"uuid":"129873203","full_name":"ltfschoen/vyper-test","owner":"ltfschoen","description":"Compile and deploy Vyper smart contracts to Truffle Develop or a private Geth Node using Web3.py, then mine the transaction and view the transaction receipt before call its functions","archived":false,"fork":false,"pushed_at":"2022-12-08T00:00:55.000Z","size":32,"stargazers_count":10,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T06:21:44.180Z","etag":null,"topics":["deployment","dockerfile","ethereum","geth-console","geth-node","mist","private-blockchain","pyenv","pytest","python36","travis-ci","vyper-contract","vyper-contracts","web3py"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ltfschoen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-17T08:37:59.000Z","updated_at":"2025-02-06T06:02:49.000Z","dependencies_parsed_at":"2022-08-29T10:41:01.955Z","dependency_job_id":null,"html_url":"https://github.com/ltfschoen/vyper-test","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltfschoen%2Fvyper-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltfschoen%2Fvyper-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltfschoen%2Fvyper-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltfschoen%2Fvyper-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ltfschoen","download_url":"https://codeload.github.com/ltfschoen/vyper-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249419484,"owners_count":21268645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment","dockerfile","ethereum","geth-console","geth-node","mist","private-blockchain","pyenv","pytest","python36","travis-ci","vyper-contract","vyper-contracts","web3py"],"created_at":"2024-10-01T16:27:06.809Z","updated_at":"2025-04-18T03:18:05.392Z","avatar_url":"https://github.com/ltfschoen.png","language":"Python","readme":"# README\n\nTravic CI Build Status: [![Build Status](https://api.travis-ci.org/ltfschoen/vyper-test.svg)](https://travis-ci.org/ltfschoen/vyper-test)\n\n---\nVyper smart contract language\n---\n\nThis is a very simplified implementation of https://github.com/ethereum/vyper by Vitalik Buterin under MIT licence. I have focused on including setup instructions for both macOS and using Docker including troubleshooting tips. I have created Vyper smart contracts and associated Unit Tests. I have summarised Vyper benefits and usage.\n\nTODO\n* [X] - Deploy Vyper contract to Geth Private Network\n* [X] - Deploy Vyper contract to Truffle Develop built-in blockchain\n* [ ] - Deploy Vyper contract to Ganache CLI / TestRPC - See this issue for progress: https://github.com/trufflesuite/ganache-cli/issues/511\n* [ ] - Deploy Vyper and integrate into Truffle\n  * https://github.com/ethereum/vyper/issues/459\n  * https://github.com/gakonst/ViperWeb3Deploy\n* [ ] - Review Vyper code by others\n  * https://github.com/Uniswap/contracts-vyper\n* [ ] - Implement [Safe Remote Purchases] (http://viper.readthedocs.io/en/latest/vyper-by-example.html#safe-remote-purchases)\n* [ ] - Implement [Crowdfund](http://viper.readthedocs.io/en/latest/vyper-by-example.html#crowdfund)\n* [ ] - Implement [Voting](http://viper.readthedocs.io/en/latest/vyper-by-example.html#voting)\n* [ ] - Implement [Company Stock](http://viper.readthedocs.io/en/latest/vyper-by-example.html#company-stock)\n* [ ] - Assist Lucas Cullen with VS Code Vyper extension using the Solidity one as reference\n  * https://github.com/bitcoinbrisbane/Vyper-vscode\n  * https://github.com/juanfranblanco/vscode-solidity\n\n# Table of Contents\n  * [Chapter 0 - Setup WITHOUT Docker](#chapter-0)\n  * [Chapter 1 - Setup WITH Docker](#chapter-1)\n  * [Chapter 2 - Docker Containers and Images (Show/Delete)](#chapter-2)\n  * [Chapter 3 - About Vyper](#chapter-3)\n  * [Chapter 4 - Unit Tests](#chapter-4)\n\n## Chapter 0 - Setup WITHOUT Docker \u003ca id=\"chapter-0\"\u003e\u003c/a\u003e\n\n* Install [PyEnv](https://github.com/pyenv/pyenv)\n* Clone the Vyper repo and install Vyper\n    ```bash\n    pyenv global 3.6.2\n    mkdir -p ~/code/clones \u0026\u0026 cd ~/code/clones\n    git clone https://github.com/ethereum/vyper.git;\n    cd vyper; \n    make; make test;\n    ```\n    * Troubleshooting\n        * Refer to my fork with detailed setup instructions in README_MAC.md https://github.com/ltfschoen/vyper\n* Clone this repo\n    ```bash\n    cd ~/code/clones;\n    git clone https://github.com/ltfschoen/vyper-test;\n    ```\n* Install dependencies. Fix any incompatibilities\n    ```bash\n    pip3 install -r requirements.txt\n    ```\n* Compile a Vyper contract\n    ```bash\n    vyper contracts/auctions/simple_open_auction.v.py\n    ```\n\n* Option 1: Run Deployment Script to Deploy the Vyper Smart Contract to Truffle's built-in blockchain\n    * Install Node Version Manager and switch to the latest version of Node.js (i.e. v9.8.0)\n        ```\n        nvm use v9.8.0\n        ```\n\n    * Install Truffle\n        ```\n        npm install -g truffle\n        ```\n\n    * Create new terminal tab in root of the project directory and run\n        ```bash\n        truffle develop --log\n        ```\n\n    * Modify scripts/main.py by changing `web3 = Web3(provider_ipc)` (used for a Geth Node) to `web3 = Web3(provider_http)` (used for Truffle) instead \n    \n    * Run the script\n        ```bash\n        python3 scripts/main.py\n        ```\n    \n    * Output after deploying the contract shown in the Truffle logs\n        ```bash\n        $ truffle develop --log\n        Truffle Develop started at http://localhost:9545/\n\n        Accounts:\n        (0) ...\n        (1) ...\n\n        Private Keys:\n        (0) ...\n        (1) ...\n\n        Mnemonic: ...\n\n        develop:testrpc personal_listAccounts +0ms\n        develop:testrpc eth_accounts +8ms\n        develop:testrpc eth_accounts +7ms\n        develop:testrpc personal_listAccounts +6ms\n        develop:testrpc eth_gasPrice +5ms\n        develop:testrpc eth_estimateGas +12ms\n        develop:testrpc net_version +48ms\n        develop:testrpc net_version +6ms\n        develop:testrpc eth_sendTransaction +7ms\n        develop:testrpc  +52ms\n        develop:testrpc   Transaction: 0x3d29ae2796e9b94f59d7830062f081fff4f9811c0869e659e2faa4efe7370ccf +0ms\n        develop:testrpc   Contract created: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0 +0ms\n        develop:testrpc   Gas usage: 273163 +0ms\n        develop:testrpc   Block Number: 1 +0ms\n        develop:testrpc   Block Time: Fri Apr 20 2018 13:01:53 GMT+1000 (AEST) +0ms\n        develop:testrpc  +0ms\n        develop:testrpc eth_getTransactionReceipt +5ms\n        develop:testrpc eth_getTransactionReceipt +11ms\n        develop:testrpc eth_getBlockByNumber +29ms\n        develop:testrpc eth_call +13ms\n        develop:testrpc eth_getBlockByNumber +30ms\n        develop:testrpc eth_call +13ms\n        ```\n\n* Option 2: Run Deployment Script to Deploy the Vyper Smart Contract to Geth Private Network\n\n    * Start a Geth Node and View its Logs\n        * https://github.com/ltfschoen/geth-node\n\n    * Run the script\n        ```bash\n        python3 scripts/main.py\n        ```\n\n    * Example Terminal Output\n        ```\n        $ python3 scripts/main.py\n\n        OS Platform: darwin\n        Web3 provider: \u003cweb3.main.Web3 object at 0x10ebb6160\u003e\n        Initializing chain from provided state\n        ABI: %s [{'name': '__init__', 'outputs': [], 'inputs': [{'type': 'address', 'name': '_beneficiary'}, {'type': 'int128', 'name': '_bidding_time'}], 'constant': False, 'payable': False, 'type': 'constructor'}, {'name': 'bid', 'outputs': [], 'inputs': [], 'constant': False, 'payable': True, 'type': 'function', 'gas': 76241}, {'name': 'end_auction', 'outputs': [], 'inputs': [], 'constant': False, 'payable': False, 'type': 'function', 'gas': 56101}, {'name': 'beneficiary', 'outputs': [{'type': 'address', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 543}, {'name': 'auction_start', 'outputs': [{'type': 'int128', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 573}, {'name': 'auction_end', 'outputs': [{'type': 'int128', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 603}, {'name': 'highest_bidder', 'outputs': [{'type': 'address', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 633}, {'name': 'highest_bid', 'outputs': [{'type': 'int128', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 663}, {'name': 'ended', 'outputs': [{'type': 'bool', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 693}]\n        Address: %s b'\\xd6\\xf0\\x84\\xee\\x15\\xe3\\x8cO~\\t\\x1f\\x8d\\xd0\\xfeo\\xe4\\xa0\\xe2\\x03\\xef'\n        Contract Instance: %s \u003cethereum.tools.tester.ABIContract object at 0x1105aa5c0\u003e\n        Contract Instance with Web3: %s \u003cethereum.tools.tester.ABIContract object at 0x1105aa5c0\u003e\n        Accounts: %s 0x487F2778Ec7D0747d6E26AF80148Ec471a08b339\n        Default Account: %s 0x487F2778Ec7D0747d6E26AF80148Ec471a08b339\n        Unlocked Default Account: %s True\n        Deployed Contract Tx Hash: %d b'\\tk\\xfb.k\\xe5\\x94\\x1f\\x152\\xb3\\x14d\\x1dN6T\\xf5\\x97v(d\\xa4\\xd6DW\\x93\\xf2r\\xe1\\xe7\\xfc'\n        Mined Transaction Receipt: %s AttributeDict({'blockHash': HexBytes('0x74c26c73f9021c8aae1a6df1e283c13a2045f3c3a2b9aab1689307b1bc40c12b'), 'blockNumber': 3755, 'contractAddress': '0xc071ef1FE2f3d9b8D59C4106391b7fe417593cfa', 'cumulativeGasUsed': 273163, 'from': '0x487f2778ec7d0747d6e26af80148ec471a08b339', 'gasUsed': 273163, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'root': '0xb5b377e641e9850d2f10d631251b5431a4f34a7745aafddca52b7654fb7bb60f', 'to': None, 'transactionHash': HexBytes('0x096bfb2e6be5941f1532b314641d4e3654f597762864a4d6445793f272e1e7fc'), 'transactionIndex': 0})\n        Transaction Receipt: %s AttributeDict({'blockHash': HexBytes('0x74c26c73f9021c8aae1a6df1e283c13a2045f3c3a2b9aab1689307b1bc40c12b'), 'blockNumber': 3755, 'contractAddress': '0xc071ef1FE2f3d9b8D59C4106391b7fe417593cfa', 'cumulativeGasUsed': 273163, 'from': '0x487f2778ec7d0747d6e26af80148ec471a08b339', 'gasUsed': 273163, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'root': '0xb5b377e641e9850d2f10d631251b5431a4f34a7745aafddca52b7654fb7bb60f', 'to': None, 'transactionHash': HexBytes('0x096bfb2e6be5941f1532b314641d4e3654f597762864a4d6445793f272e1e7fc'), 'transactionIndex': 0})\n        Contract Instance: %s \u003cweb3.utils.datatypes.Contract object at 0x10f151a20\u003e\n        Called Getter method of beneficiary from Deployed Contract Instance: %s 0x487F2778Ec7D0747d6E26AF80148Ec471a08b339\n        Called Getter method of auction_end from Deployed Contract Instance: %s 1524192662\n        ```\n\n* Option 3: **INCOMPLETE (DOES NOT WORK YET)** - Deploy Vyper contract to Ganache CLI / TestRPC\n    * Create separate terminal tab and start virtual EVM and start Ganache CLI\n\n        ```bash\n        ganache-cli \\\n            --account=\"0x0000000000000000000000000000000000000000000000000000000000000001, 2471238800000000000\" \\\n            --account=\"0x0000000000000000000000000000000000000000000000000000000000000002, 4471238800000000000\" \\\n            --unlock \"0x0000000000000000000000000000000000000000000000000000000000000001\" \\\n            --unlock \"0x0000000000000000000000000000000000000000000000000000000000000002\" \\\n            --blocktime 0 \\\n            --deterministic true \\\n            --port 9545 \\\n            --hostname localhost \\\n            --seed 'blah' \\\n            --debug true \\\n            --mem true \\\n            --mnemonic 'something' \\\n            --db './db/chain_database' \\\n            --verbose \\\n            --networkId=1000 \\\n            --gasLimit=7984452 \\\n            --gasPrice=20000000000;\n        ```\n    \n    * Run the script\n        ```bash\n        python3 scripts/main.py\n        ```\n\n* Run Unit tests\n    * Troubleshooting\n        * Recursively deleting the pycache folder created in both the tests/ subdirectory and the tests/auctions/ subdirectory, and the .pytest_cache folder in the project root directory, and then running `find . -name '*.pyc' -delete` just to be sure all the cache files had been removed from all subdirectories. Add `export PYTHONDONTWRITEBYTECODE=1` into ~/.bash_profile so Python cache files would no longer be generated.\n\n    ```bash\n    python3 -m pytest -v\n    ```\n\n* Troubleshooting\n    * Refer to fork with [Troubleshooting steps](https://github.com/ltfschoen/vyper/blob/master/README_MAC.md)\n\n## Chapter 1 - Setup WITH Docker \u003ca id=\"chapter-1\"\u003e\u003c/a\u003e\n\n* Install and Run Docker\n* Fork my repo https://github.com/ltfschoen/vyper\n* Terminal #1 - Clone the fork\n\n    ```bash\n    cd ~;\n    git clone https://github.com/ltfschoen/vyper;\n    cd vyper;\n    ```    \n\n* Terminal #1 - Build the custom DockerfileMac. This allows file changes in the Docker container to be synchronised with your host machine and vice versa.\n\n    ```bash\n    docker build -t vyper:1 . -f DockerfileMac\n    ```\n\n* Terminal #2 - Create another Bash terminal window/tab in the same folder\n\n* Terminal #2 - Open the directory in a Text Editor or IDE\n\n* Terminal #1 - Start a shell session in the Docker container that you just created.\n    \n    ```bash\n    docker run -it -v $(pwd):/code vyper:1 /bin/bash\n    ```\n\n* Terminal #1 (within Docker Container shell session) - Compile a Vyper contract\n    ```bash\n    vyper examples/crowdfund.v.py\n    ```\n\n* Make changes to examples/crowdfund.v.py in the Text Editor. The changes will also be reflected in the Docker Container.\n\n* Terminal #1 - Repeat the previous command to try and re-compile the Vyper contract\n\n* Follow steps in Chapter 0 to clone my repo and make the files accessible in the container\n\n## Chapter 2 - Docker Containers and Images (Show/Delete) \u003ca id=\"chapter-2\"\u003e\u003c/a\u003e\n\n* List all Docker containers \n    ```bash\n    docker ps -a\n    ```\n\n* Stop all running containers. \n    ```bash\n    docker stop $(docker ps -aq)\n    ```\n\n* Remove a specific Docker container\n    ```bash\n    docker rm \u003cCONTAINER_ID\u003e\n    ```\n* Remove a docker container \n    ```bash\n    docker rm $(docker ps -aq)\n    ```\n\n* Remove all Docker images\n    ```bash\n    docker rmi $(docker images -q)\n    ```\n\n## Chapter 3 - About Vyper \u003ca id=\"chapter-3\"\u003e\u003c/a\u003e\n\n* Vyper Online Compilter (to bytecode or LLL) https://vyper.online/\n\n* Vyper Features (vs Solidity)\n    * Asserts instead of Modifiers\n        * Pros\n            * No arbitrary pre-conditions, no post-conditions\n            * No arbitrary state changes\n            * Less execution jumps for easier auditability\n    * No Class Inheritance\n    * No Function or Operator Overloading \n        * Pros\n            * Safer since mitigates funds being stolen \n    * No Recursive Calling or Infinite-length Loops\n        * Pros \n            * Avoids gas limit attacks since gas limit upper bound may be set\n    * `.v.py` File Extension so Python syntax highlighting may be used\n    * All Vyper syntax is valid Python 3 syntax, but not all Python 3 functionality is available in Vyper\n    * Reference\n        * http://viper.readthedocs.io/en/latest/\n\n\n* Vyper Syntax where Files `.v.py` are a Smart Contract \n    * Class-like with:\n        * Contract State Variables\n            * Usage: Permanently stored in contract Storage\n            * Example\n                ```python\n                storedData: int128\n                ```\n            * Access \n                ```python\n                self.storedData\n                ```\n        * Validations \n            * `assert`\n                * Failure to pass results in the method to throw an error and the transaction is reverted\n        * Objects\n            * `block` - Object available within Vyper contract providing info about block at time of calling\n            * `msg`\n                * Object built-in that provides information about the message caller whenever a method in the contract is called\n                * `msg.sender` to access public address of the caller of a method\n                    * WARNING: If calling contract from outside it works correctly, but for subsequent internal function calls it will reference the contract itself instead of the sender of the transaction\n                * `msg.value` to access amount of ether a user sends\n        * [Types, Visibility, Getters](http://viper.readthedocs.io/en/latest/types.html#types)\n            * `address`\n            * `bool`\n            * `timedelta` seconds\n            * `timestamp` time\n                * `block.timestamp` - Current Time\n            * `wei_value` lowest denominator\n            \n        * Functions\n            * Usage: \n                * Executable units in contract\n                * Internally or Externally\n                * Visibility-and-getters differ toward other contracts\n                * Decorated with `@public` or `@private`\n                    * Default is `@private` which is only accessible to methods in same contract\n                    * `@public` callable by external contracts\n                    * `@public` function creates a **Getter** function accessible with call `self.get_beneficiary(some_address)`\n\n                * **Security** Structure functions that interact with other contracts (i.e. they call functions or send Ether) into three phases:\n                    * 1. Check Conditions\n                    * 2. Performing Actions (potentially changing conditions)\n                    * 3. Interacting with other Contracts\n                    * WARNING: If these phases are mixed up, the other contract could call back into the current contract and modify the state or cause effects (Ether payout) to be performed multiple times. If functions called internally include interaction with external contracts, they also have to be considered interaction with external contracts.\n            * Example\n                ```python\n                @public\n                @payable\n                def bid(): // Function\n                // ...\n                ```\n        * Events\n            * Usage\n                * Searchable by Clients and Light Clients since Events are logged in specially indexed data structures\n                * Declared before global declarations and Function definitions\n            * Example\n                ```python\n                Payment: event({amount: int128, arg2: indexed(address)})\n\n                total_paid: int128\n\n                @public\n                def pay():\n                    self.total_paid += msg.value\n                    log.Payment(msg.value, msg.sender)\n                ```\n        * Structs\n            * TODO\n\n## Chapter 4 - Unit Tests \u003ca id=\"chapter-4\"\u003e\u003c/a\u003e\n\n```bash\npip3 install ethereum==2.3.1 pytest pytest-cov pytest-runner\npython setup.py test\npytest -v --full-trace --setup-show\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fltfschoen%2Fvyper-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fltfschoen%2Fvyper-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fltfschoen%2Fvyper-test/lists"}