What we plan on accomplishing:
As with everything, documentation is lacking and it took me a few days to find all of the resources to deploy an example smart contract and find the necessary resources. I'm hoping that this will help students and developers to quickly get going with all of the resources necessary to start doing development work on Blockchain, in python, quickly. That said, this "guide", may not be complete, may not be accurate (especially since things are evolving so rapidly), but it is my guide from not having an address or account anywhere, to deploying a smart vyper contract and interacting with it in CLI. Consider it a cheat sheet on how to get started fast. We will be doing everything free, so we will be using the "Ropsten Testnet Network" and for completeness, we'll be using vyper most complete example for smart contract, their company stock example. From their website: This contract is just a tad bit more thorough than the ones we’ve previously encountered. In this example, we are going to look at a comprehensive contract that manages the holdings of all shares of a company. The contract allows for a person to buy, sell and transfer shares of a company as well as allowing for the company to pay a person in ether. The company, upon initialization of the contract, holds all shares of the company at first but can sell them all. Currently, most smart contracts are written in solidity and vyper. Solidity follows javascript, while vyper is more pythonic. Older, no longer supported, or rarely updated languages include Mutan, LLL, Serpant, and Bamboo. While solidity is akin to the 800 pound gorilla, vyper has some strong benefits and focuses on security and has been well studied (pdf) and actively maintained. So without further adieu, lets begin. TL;DR....
pip3 install web3 from web3 import Web3 infura_url = "https://ropsten.infura.io/v3/<PROJECT ID>" web3 = Web3(Web3.HTTPProvider(infura_url)) my_account = web3.eth.account.create('Awesome test') print(f"Web3 is connected?: {web3.isConnected()}")
Note: my_account will then have your: my_account.address, my_account.key, and my_account.privateKey
Your web3, should show as connected, returning a True. You can also create a wallet from places like, https://www.myetherwallet.com. If you made your key manually and have a text file, for example, `UTC--2021-04-26T20-00-11.234Z--ABCDEFGHIJKLMNOP`, you can create your private key as follows: with open('UTC--2021-04-26T20-00-11.234Z--ABCDEFGHIJKLMNOP') as keyfile: encrypted_key = keyfile.read() private_key = web3.eth.account.decrypt(encrypted_key, '<SUPER SECURE PASSWORD HERE USED AT CREATION>')
4. Go to https://faucet.ropsten.be/ and enter your address. This will give you a test Ether.
5. Go to https://ropsten.etherscan.io and verify that your account now has one test Ether. 6. Go to https://www.myetherwallet.com (MEW)and connect to your account. If you followed the steps above, you can enter your private key into the "Access by Software" section on the website and entering your private key in hex form: `print(my_account.privateKey.hex())` Since none of us are bitcoin millionaires and this is for testing purposes, I don't mind the relaxed security for testing. If there is ANY real currency, I highly recommend other, more secure, approaches. MEW is a nice tool to easily view 1. that you have received your test ethers, 2. displaying & 3. deploying smart contracts, and 4. viewing transactions. The above 6 steps are essential in getting you started and paving the way for starting your development work in Blockchain technology. In the next part, we will deploy our smart contract, and create some simple code to start interacting with it. Resources: |
AuthorJames Benson is an IT professional. Archives
August 2022
Categories
All
|