Skip to content

Commit 2530fe3

Browse files
Update index.md (#9796)
update fromWei and toWei to the new from_wei and to_wei syntax
1 parent 1ea0aac commit 2530fe3

File tree

1 file changed

+5
-5
lines changed
  • src/content/developers/tutorials/a-developers-guide-to-ethereum-part-one

1 file changed

+5
-5
lines changed

src/content/developers/tutorials/a-developers-guide-to-ethereum-part-one/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ In [1]: from web3 import Web3
124124

125125
Besides being a gateway to Ethereum, the [Web3](https://web3py.readthedocs.io/en/stable/overview.html#base-api) module offers a few convenience functions. Let’s explore a couple.
126126

127-
In an Ethereum application, you will commonly need to convert currency denominations. The Web3 module provides a couple of helper methods just for this: [fromWei](https://web3py.readthedocs.io/en/stable/web3.main.html#web3.Web3.fromWei) and [toWei](https://web3py.readthedocs.io/en/stable/web3.main.html#web3.Web3.toWei).
127+
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.from_wei) and [to_wei](https://web3py.readthedocs.io/en/stable/web3.main.html#web3.Web3.to_wei).
128128

129129
<div class="featured">
130130
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.
@@ -140,10 +140,10 @@ A similar pattern is used when handling transactions in <b>ether</b>. However, i
140140
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.
141141

142142
```python
143-
In [2]: Web3.toWei(1, 'ether')
143+
In [2]: Web3.to_wei(1, 'ether')
144144
Out[2]: 1000000000000000000
145145

146-
In [3]: Web3.fromWei(500000000, 'gwei')
146+
In [3]: Web3.from_wei(500000000, 'gwei')
147147
Out[3]: Decimal('0.5')
148148
```
149149

@@ -211,7 +211,7 @@ Out[7]: 1000000000000000000000000
211211
That’s a lot of zeros! Before you go laughing all the way to the fake bank, recall that lesson about currency denominations from earlier. Ether values are represented in the smallest denomination, wei. Convert that to ether:
212212

213213
```python
214-
In [8]: w3.fromWei(1000000000000000000000000, 'ether')
214+
In [8]: w3.from_wei(1000000000000000000000000, 'ether')
215215
Out[8]: Decimal('1000000')
216216
```
217217

@@ -246,7 +246,7 @@ We’re stuck at block zero until there’s a pending transaction, so let’s gi
246246
In [10]: tx_hash = w3.eth.send_transaction({
247247
'from': w3.eth.accounts[0],
248248
'to': w3.eth.accounts[1],
249-
'value': w3.toWei(3, 'ether'),
249+
'value': w3.to_wei(3, 'ether'),
250250
'gas': 21000
251251
})
252252
```

0 commit comments

Comments
 (0)