Lesson 19 of 21
In Progress

Recap of Key Hardhat Concepts

In this course, you learned how to use Hardhat to develop and deploy decentralized applications on the Ethereum blockchain. You learned how to set up your development environment, write and test Solidity contracts, deploy contracts to the blockchain, interact with deployed contracts, and manage your deployments with migrations. You also learned about advanced testing and debugging techniques, as well as how to integrate your DApp with a front-end framework.

By now, you should have a strong understanding of the key concepts and techniques needed to develop and deploy DApps using Hardhat. You are well on your way to becoming a proficient blockchain developer!

What is Next?

To further your skills, consider exploring the following resources:

  • The Hardhat documentation: This is an excellent resource for learning more about the various features and options available in Hardhat.
  • Ethereum development forums and communities: There are many online communities dedicated to Ethereum development, where you can ask questions, seek help, and share your projects with other developers.
  • Other Ethereum development tools: Hardhat is just one of many tools available for developing on the Ethereum platform. Consider exploring other tools such as Truffle, Embark, and OpenZeppelin to expand your skills and knowledge.

Remember to keep practicing and learning, and you’ll be an expert blockchain developer in no time!

Exercises

To review these concepts, we will go through a series of exercises designed to test your understanding and apply what you have learned.

Write a Solidity contract that defines a struct called Person with fields for a name, age, and address. Write a function that allows you to set the values of the struct.

pragma solidity ^0.8.0;

contract MyContract {
    struct Person {
        string name;
        uint age;
        address address;
    }
    Person public person;

    function setPerson(string memory _name, uint _age, address _address) public {
        person.name = _name;
        person.age = _age;
        person.address = _address;
    }
}

Write a migration script that deploys the contract you created in exercise 1 and then calls the function to set the values of the struct.

const MyContract = artifacts.require("MyContract");

module.exports = async function(deployer) {
  await deployer.deploy(MyContract);
  const contract = await MyContract.deployed();
  await contract.setPerson("Alice", 25, "0x123456");
}

Write a Hardhat script that calls the function of your contract to retrieve the values of the struct and print them to the console.

const MyContract = artifacts.require("MyContract");

module.exports = async function(callback) {
  const contract = await MyContract.deployed();
  const person = await contract.person();
  console.log(person);
}

Write a Solidity contract that defines a mapping from addresses to integers. Write a function that allows you to increment the value associated with an address.

pragma solidity ^0.8.0;

contract MyContract {
    mapping(address => uint) public values;

    function increment(address _address) public {
        values[_address]++;
    }
}

Write a Hardhat script that calls the function of your contract to increment the value for two different addresses and then retrieves and prints the values for those addresses.

const MyContract = artifacts.require("MyContract");

module.exports = async function(callback) {
  const contract = await MyContract.deployed();
  await contract.increment("0x123456");
  await contract.increment("0x654321");
  const value1 = await contract.values("0x123456");
  const value2 = await contract.values("0x654321");
  console.log(value1);
  console.log(value2);
}