Coder Social home page Coder Social logo

lesson-04's Introduction

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

lesson-04's People

Contributors

matheusdaros avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.