Skip to content

Encode-Club-Solidity-Foundations/Lesson-04

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Lesson 4 - Interfaces and external calls

External calls

  • What is a “MethodID”
  • Fallback and receive functions
  • External calls

References

https://docs.soliditylang.org/en/latest/control-structures.html#external-function-calls

https://solidity-by-example.org/function-selector/

Using interfaces

  • Fallback and receive functions
  • External calls
  • Attaching “mismatched” contracts
  • Why some functions work and others don’t because of the “MethodID”

Restricting access to functions

  • Wrapping up contents
    • Modifier
    • Assertion inside modifiers
    • Message Sender
    • Visibility
    • Mutability
  • Implementing basic access control on setText

References

https://docs.soliditylang.org/en/latest/common-patterns.html#restricting-access

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract HelloWorld {
    string private text;
    address public owner;

    constructor() {
        text = "Hello World";
        owner = msg.sender;
    }

    function helloWorld() public view returns (string memory) {
        return text;
    }

    function setText(string calldata newText) public onlyOwner {
        text = newText;
    }

    function transferOwnership(address newOwner) public onlyOwner {
        owner = newOwner;
    }

    modifier onlyOwner()
    {
        require (msg.sender == owner, "Caller is not the owner");
        _;
    }
}

Contract interaction

  • Interacting with previously deployed contracts using interfaces
  • Inspecting “MethodId” mismatch and fallback functions
  • Inspecting execution errors based on assertions
  • Fixing the interfaces
  • Interacting with other peoples contract

Extra reference material

Homework

  • Create Github Issues with your questions about this lesson
  • Read the references

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published