{"id":20008317,"url":"https://github.com/bethanyuo/web3py-contract","last_synced_at":"2026-05-25T16:02:06.613Z","repository":{"id":116556850,"uuid":"278962764","full_name":"bethanyuo/web3py-contract","owner":"bethanyuo","description":"Deploy and interact with a Smart Contract using Web3.py.","archived":false,"fork":false,"pushed_at":"2020-07-12T00:59:48.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T01:31:06.079Z","etag":null,"topics":["infura","python","smart-contracts","web3","web3py"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bethanyuo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-12T00:16:05.000Z","updated_at":"2021-11-20T21:39:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"d94cf2f5-7038-4cf8-9ca3-f311cd01419c","html_url":"https://github.com/bethanyuo/web3py-contract","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bethanyuo/web3py-contract","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bethanyuo%2Fweb3py-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bethanyuo%2Fweb3py-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bethanyuo%2Fweb3py-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bethanyuo%2Fweb3py-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bethanyuo","download_url":"https://codeload.github.com/bethanyuo/web3py-contract/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bethanyuo%2Fweb3py-contract/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33482411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["infura","python","smart-contracts","web3","web3py"],"created_at":"2024-11-13T07:09:20.898Z","updated_at":"2026-05-25T16:02:06.592Z","avatar_url":"https://github.com/bethanyuo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart Contracts using Web3.py\nUse the `web3.py` library for interacting with Ethereum. Its API is derived from the `Web3.js` JavaScript API and should be familiar to anyone who has used `web3.js`. The exercise will show how to interact with an already deployed contract on the Ethereum Ropsten Testnet.\n## Set up environment\nWeb3.py requires Python 3. It can be installed using pip as follows:\n```sh\n$ pip install web3\n```\nCreate a new Python file and import the following:\n```py\nfrom web3 import Web3, HTTPProvider\n```\nWe will need `HTTPProvider` in order to create our connection to the Ropsten Testnet using `Infura.io`.\nNow let’s get the necessary Infura.io provider. Go to https://infura.io/ and copy the Ropsten URL.\n```py\nPROVIDER = \"https://rospten.infura.io/\u003cENDPOINT-ID\u003e\"\nw3 = Web3(HTTPProvider(PROVIDER))\n```\n \nIn order to get a contract instance of an already deployed contract, we will need its `address` and `application binary interface`. For this exercise’s purpose, deploy a simple contract storing an array of facts through `Remix IDE` using MetaMask Ropsten as a provider.\n\nIf you do not have ETHt, use the MetaMask faucet: https://faucet.metamask.io/.\n\nThen, copy its `address` and `ABI`, and create an instance of the contract. Json library will be needed to the decode the ABI:\n```py\nCONTRACT_INSTANCE = w3.eth.contract(CONTRACT_ADDRESS, abi=json.loads(ABI))\n```\n## Writing to the Smart Contract\nNow that there is an instance of the contract, create a method for writing facts in the smart contract. It will need the instance, a `private key/wallet`, the address of the `private key/wallet` and the `fact`. The library `is not recommended` to work with Local Private Keys in `Production` at the moment, so for the exercise we will enable the _unaudited features_. \n```py\nw3.eth.enable_unaudited_features()\n```\nBecause the `contract owner` can only add facts to this contract, copy the private key and address. The address will be needed to easily calculate the `nonce`.\nWe will create a simple transaction, which `adds a fact` to the contract, `sign it` with the private key and `send it`.\n\nTry adding a fact using another private key. _RESULT: `FAIL`_\n## Reading from the Smart Contract\nWhen reading from a Smart Contract, no wallets or private keys are needed. \nFirst, create a method which gets a fact by a given `index`. Then, create a method which gets `how many facts` are stored in the contract.\n```\n$ python3 main.py\nFact 1: The Times 03/Jan/2009 Chancellor on brink of second bailout for banks\nStored facts in the contract: 1\n```\n## Module\nMI4: Module 5: E6\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbethanyuo%2Fweb3py-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbethanyuo%2Fweb3py-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbethanyuo%2Fweb3py-contract/lists"}