1/5
## As Wei Value In this lesson, we're going to look at the `as_wei_value()` function within solidity. Let's say we have a smart contract that requires a minimum USD value to be sent to it. In this case, that minimum amount is 5 USD. ```python self.minimum_usd = 5 ``` However, this can be an issue because we're working in Ethereum, and the units of value are in Ether. ```python usd_value_of_eth: uint256 = self.get_eth_to_usd_rate(msg.value) assert usd_value_of_eth >= self.minimum_usd, "You must spend more ETH!" ``` Remember, ETH has 18 decimal places. So, a value of 5 USD will not be represented as 5 in this context. Instead, we'll need to convert the value of 5 USD into Ether (WEI). ```python self.minimum_usd = 5 * (10 ** 18) ``` We can also do this: ```python self.minimum_usd = 5000000000000000000 ``` However, this is not a readable way to present the code. Instead, we can use the function `as_wei_value()` to make the code much more legible. ```python self.minimum_usd = as_wei_value(5, "ether") ``` We can now use this new minimum USD value (in WEI) for our assertions: ```python assert usd_value_of_eth >= self.minimum_usd, "You must spend more ETH!" ``` This `as_wei_value()` function is a great shortcut for adding those 18 decimal places. courses\vyper-101\2-remix-coffee\20-as-wei-value\+page.md
A simple guide to using `as_wei_value()` in Vyper - This lesson shows you how to use the `as_wei_value()` function to represent a dollar amount in Wei to set a minimum dollar amount to send to a contract.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 15, 2025
Vyper Developer
Introduction to Python and VyperDuration: 2h 08min
Duration: 2h 32min
Duration: 24min
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 15, 2025