1/5
### Creating the Vault Contract and Natspec Comments Okay, let�s quickly address our comments before we move on. Notice how our comments don't have nice pretty colors. That's not very helpful. We forgot to add the second star so: ```javascript /** * @notice Set the interest rate in the contract * @param _newInterestRate The new interest rate to set * @dev The interest rate can only decrease */ ``` If we do a slash star star it will do nice colors for our natspecs. ```javascript /** * @notice Get the principle balance of a user. This is the number of tokens that have currently been minted to the user, no * @param _user The user to get the principle balance for * @return The principle balance of the user */ ``` We can go through and add this to all of the comments, the natspec comments on our functions. The next thing we need to do, is like we were saying earlier, we just closed our lib, we need to create the vault. This is going to be the place where our users come to deposit their ETH and then withdraw their ETH. It is also going to be the place where the rewards are going to be sent. It�s just, basically, a place to lock up all of the ETH in one place. So we're going to create a new file called: ```javascript Vault.sol ``` Then we need to add SPDX license identifier: ```javascript // SPDX-License-Identifier: MIT ``` Then we'll add our pragma solidity version: ```javascript pragma solidity �0.8.24�; ``` Now, we can start writing the contract: ```javascript contract Vault { } ``` We are going to need to pass the token address to the constructor so we can mint and burn. We need to create a deposit function that mints tokens to the user and a redeem function that burns tokens from the user and sends the user the ETH. We also need a way to add rewards to the vault.
A comprehensive guide to building a Vault contract in Solidity. This lesson covers the fundamentals of creating a Vault contract, including how to pass in the token address to the constructor, create deposit and redeem functions, add rewards to the vault, implement a receive() function, and utilize interfaces to interact with other contracts.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on March 11, 2025
Solidity Developer
Advanced FoundryDuration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 6h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 1h 10min
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on March 11, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar