Exercise - Demonstrate your knowledge of storage.
Create a contract that adheres to the following specifications:
Create a single contract called EmployeeStorage
. It should not inherit from any other contracts. It should have the following functions:
The contract should have the following state variables, optimized to minimize storage:
shares
storing the employee’s number of shares owned
name
which stores the employee’s namesalary
storing the employee’s salary
idNumber
storing the employee’s ID number
When deploying the contract, utilize the constructor
to set:
shares
name
salary
idNumber
For the purposes of the test, you must deploy the contract with the following values:
shares
- 1000name
- Patsalary
- 50000idNumber
- 112358132134In the world of blockchain, nothing is ever secret!* private
variables prevent other contracts from reading the value. You should use them as a part of clean programming practices, but marking a variable as private does not hide the value. All data is trivially available to anyone who knows how to fetch data from the chain.
*You can make clever use of encryption though!
Write a function called viewSalary
that returns the value in salary
.
Write a function called viewShares
that returns the value in shares
.
Add a public function called grantShares
that increases the number of shares allocated to an employee by _newShares
. It should:
shares
TooManyShares
that returns the number of shares the employee would have with the new amount added_newShares
is greater than 5000, revert with a string message, “Too many shares”Add the following function to your contract exactly as written below.
Testnets are not permanent! Base Goerli will soon be sunset, in favor of Base Sepolia.
As these are separate networks with separate data, your NFTs will not transfer over.
Don’t worry! We’ve captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you’d like!