You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/lessons/fundamentals/wolovim-part-1.mdx
+28-20Lines changed: 28 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,8 +45,9 @@ There are many ways to describe Ethereum, but at its heart is a blockchain. Bloc
45
45
46
46
Each block has a reference to the block that came before it; the `parentHash` is simply the hash of the previous block.
47
47
48
-
> Note: Ethereum makes regular use of hash functions to produce fixed-size values (“hashes”). Hashes play an important role in Ethereum, but you can safely think of them as unique IDs for now.
49
-
>
48
+
<Calloutemoji='💡'size='md'variant='info'>
49
+
**Note:** Ethereum makes regular use of hash functions to produce fixed-size values (“hashes”). Hashes play an important role in Ethereum, but you can safely think of them as unique IDs for now.
@@ -60,18 +61,19 @@ The only way for the blockchain to verify that asset was truly sent from one use
60
61
61
62
This new decentralized tech stack has spawned new developer tools. Such tools exist in many programming languages, but we’ll be looking through the Python lens. To reiterate: even if Python isn’t your language of choice, it shouldn’t be much trouble to follow along.
62
63
63
-
Python developers that want to interact with Ethereum are likely to reach for **[Web3.py](https://web3py.readthedocs.io/)**. Web3.py is a library that greatly simplifies the way you connect to an Ethereum node, then send and receive data from it.
64
+
Python developers that want to interact with Ethereum are likely to reach for **[web3.py](https://web3py.readthedocs.io/)**. web3.py is a library that greatly simplifies the way you connect to an Ethereum node, then send and receive data from it.
64
65
65
-
> Note: “Ethereum node” and “Ethereum client” are often used interchangeably. In either case, it refers to the software that a participant in the Ethereum network runs. This software can read block data, receive updates when new blocks are added to the chain, broadcast new transactions, and more.
66
-
>
66
+
<Calloutemoji='💡'size='md'variant='info'>
67
+
**Note:** “Ethereum node” and “Ethereum client” are often used interchangeably. In either case, it refers to the software that a participant in the Ethereum network runs. This software can read block data, receive updates when new blocks are added to the chain, broadcast new transactions, and more.
68
+
</Callout>
67
69
68
-
Ethereum clients can be configured to be reachable by [IPC](https://en.wikipedia.org/wiki/Inter-process_communication), HTTP, or Websockets. Web3.py refers to these connection options as **providers**. You’ll want to choose one of the three providers to configure so that Web3.py knows how to communicate with your node.
70
+
Ethereum clients can be configured to be reachable by [IPC](https://en.wikipedia.org/wiki/Inter-process_communication), HTTP, or Websockets. web3.py refers to these connection options as **providers**. You’ll want to choose one of the three providers to configure so that web3.py knows how to communicate with your node.
Configure the Ethereum node and Web3.py to communicate via the same protocol, e.g., IPC in this diagram.
74
+
Configure the Ethereum node and web3.py to communicate via the same protocol, e.g., IPC in this diagram.
73
75
74
-
Once Web3.py is properly configured, you can begin to interact with the blockchain. Here’s a couple of Web3.py usage examples as a preview of what’s to come:
76
+
Once web3.py is properly configured, you can begin to interact with the blockchain. Here’s a couple of web3.py usage examples as a preview of what’s to come:
In this walkthrough, we’ll just be working within a Python interpreter. We won't be creating any directories, files, classes or functions.
87
89
88
-
> Note: In the examples below, commands that begin with $ are intended to be run in the terminal. (Do not type the $, it just signifies the start of the line.)
89
-
>
90
+
<Calloutemoji='💡'size='md'variant='info'>
91
+
**Note:** In the examples below, commands that begin with `$` are intended to be run in the terminal. (Do not type the `$`, it just signifies the start of the line.)
92
+
</Callout>
90
93
91
-
First, install [IPython](https://ipython.org/) for a user-friendly environment to explore in. IPython offers tab completion, among other features, making it much easier to see what’s possible within Web3.py.
94
+
First, install [IPython](https://ipython.org/) for a user-friendly environment to explore in. IPython offers tab completion, among other features, making it much easier to see what’s possible within web3.py.
92
95
93
96
```bash
94
97
$ pip install ipython
95
98
```
96
99
97
-
Web3.py is published under the name `web3`. Install the latest version like so:
100
+
web3.py is published under the name `web3`. Install the latest version like so:
98
101
99
102
```bash
100
-
$ pip install web3==6.0.0b8
103
+
$ pip install web3
101
104
```
102
105
103
106
One more thing – we're going to simulate a blockchain later, which requires a couple more dependencies. You can install those via:
@@ -134,8 +137,13 @@ Besides being a gateway to Ethereum, the [Web3](https://web3py.readthedocs.io/e
134
137
135
138
In an Ethereum application, you will commonly need to convert currency denominations. The Web3 module provides a couple of helper methods just for this: [from_wei](https://web3py.readthedocs.io/en/stable/web3.main.html#web3.Web3.fromWei) and [to_wei](https://web3py.readthedocs.io/en/stable/web3.main.html#web3.Web3.toWei).
136
139
137
-
> Note: Computers are notoriously bad at handling decimal math. To get around this, developers often store dollar amounts in cents. For example, an item with a price of $5.99 may be stored in the database as 599.A similar pattern is used when handling transactions in ether. However, instead of two decimal points, ether has 18! The smallest denomination of ether is called wei, so that’s the value specified when sending transactions.1 ether = 1000000000000000000 wei1 wei = 0.000000000000000001 ether
138
-
>
140
+
<Calloutemoji='💡'size='md'variant='info'>
141
+
**Note:** Computers are notoriously bad at handling decimal math. To get around this, developers often store dollar amounts in cents. For example, an item with a price of $5.99 may be stored in the database as 599. A similar pattern is used when handling transactions in ether. However, instead of two decimal points, ether has 18! The smallest denomination of ether is called *wei*, so that’s the value specified when sending transactions.
142
+
143
+
1 ether = 1000000000000000000 wei
144
+
145
+
1 wei = 0.000000000000000001 ether
146
+
</Callout>
139
147
140
148
Try converting some values to and from wei. Note that there are [names for many of the denominations](https://web3py.readthedocs.io/en/stable/examples.html#converting-currency-denominations) in between ether and wei. One of the better known among them is **gwei**, as it’s often how transaction fees are represented.
141
149
@@ -151,22 +159,22 @@ Other utility methods on the Web3 module include data format converters (e.g.,
151
159
152
160
### **Talk to the chain**
153
161
154
-
The convenience methods are lovely, but let’s move on to the blockchain. The next step is to configure Web3.py to communicate with an Ethereum node. Here we have the option to use the IPC, HTTP, or Websocket providers.
162
+
The convenience methods are lovely, but let’s move on to the blockchain. The next step is to configure web3.py to communicate with an Ethereum node. Here we have the option to use the IPC, HTTP, or Websocket providers.
155
163
156
164
We won't be going down this path, but an example of a complete workflow using the HTTP Provider might look something like this:
157
165
158
166
- Download an Ethereum node, e.g., [Geth](https://geth.ethereum.org/).
159
167
- Start Geth in one terminal window and wait for it to sync the network. The default HTTP port is `8545`, but is configurable.
160
-
- Tell Web3.py to connect to the node via HTTP, on `localhost:8545`.`w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))`
168
+
- Tell web3.py to connect to the node via HTTP, on `localhost:8545`.`w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))`
161
169
- Use the `w3` instance to interact with the node.
162
170
163
-
While this is one “real” way to do it, the syncing process takes hours and is unnecessary if you just want a development environment. Web3.py exposes a fourth provider for this purpose, the **EthereumTesterProvider**. This tester provider links to a simulated Ethereum node with relaxed permissions and fake currency to play with.
171
+
While this is one “real” way to do it, the syncing process takes hours and is unnecessary if you just want a development environment. web3.py exposes a fourth provider for this purpose, the **EthereumTesterProvider**. This tester provider links to a simulated Ethereum node with relaxed permissions and fake currency to play with.
The EthereumTesterProvider connects to a simulated node and is handy for quick development environments.
168
176
169
-
That simulated node is called [**eth-tester**](https://github.com/ethereum/eth-tester) and we installed it as part of the `pip install "web3[tester]"` command. Configuring Web3.py to use this tester provider is as simple as:
177
+
That simulated node is called [**eth-tester**](https://github.com/ethereum/eth-tester) and we installed it as part of the `pip install "web3[tester]"` command. Configuring web3.py to use this tester provider is as simple as:
170
178
171
179
```python
172
180
In [4]: w3 = Web3(Web3.EthereumTesterProvider())
@@ -284,7 +292,7 @@ The latter looks good! The balance went from 1,000,000 to 1,000,003 ether. But w
284
292
285
293
<Calloutemoji='💡'size='md'variant='info'>
286
294
**Note**: On the public network, transaction fees are variable based on network demand and how quickly you'd like a transaction to be processed.
0 commit comments