Environment variables
There are environment variables that describe the block properties and the transaction. If you want to know which block you are in right now (remember that a smart contract lives in the blockchain), you can retrieve it from block.number
. If you are keen to know the number of ethers that a user sends to a smart contract, you can use msg.value
. If you are curious to know who sends money, you can query the information from msg.sender
. If you want to store the time when a user sends ethers, you can use block.timestamp
.
To demonstrate the environment variables, let’s create a Vyper file, named EnvVar.vy
, and add the following code to it:
# @version ^0.3.0 donatur: address donation: uint256 time: uint256 @external @payable def donate(): self.donatur = msg.sender self.donation = msg.value self.time = block.timestamp
When a user executes the donate
function, they can send ethers or...