My Image
CoursesQuizzesProblemsContestsSmartBooks
Contest!

No results found

LOGINREGISTER
My ProgressCoursesQuizzesProblemsContestsSmartbooks
Published on 6 Jul 2021
Working of external visibility in functions
external visibility with the help of contract instance
img
Anurag Saini
0
Like
88

Visibility

Function and state variables have to declare whether they are accessible by other contracts.

  • external - External functions are meant to be called by other contracts. They cannot be used for internal calls. To call an external function within contract this.function_name() call is required. State variables cannot be marked as external. 

        --- Only other contracts and accounts can call

  • public - Public function/ Variables can be used both externally and internally. For public state variables, Solidity automatically creates a getter function.

       --- any contract and account can call

  • internal - Internal function/ Variables can only be used internally or by derived contracts.

    --- only inside the contract that inherits as an internal function.

  • private - Private function/ Variables can only be used internally and not even by derived contracts.

 

Example:-

pragma solidity ^0.8.0;

contract Test{

function A() external pure returns(string memory) {
return "It's me Anurag";
    }
}

contract Test2{

// contract instance
Test test = new Test();

// public - if you deploy it they will show the return value and in public, anyone can call it.
function B() public view returns(string memory) {
return test.A();
   }

// private - private keyword don't show the return value.
function C() private view returns(string memory) {
return test.A();
    }

// internal - only connect with internal or derived contracts.
function D() internal view returns(string memory) {
return test.A();
  }

//external - only call other contract.
function E() external view returns(string memory) {
return test.A();
 }

}

 

Enjoyed the SmartBook?
Like
logo
contact@dapp-world.com
Katraj, Pune, Maharashtra, India - 411048

Follow Us

linkedintwitteryoutubediscordinstagram

Products

  • SmartBooks
  • Courses
  • Quizzes
  • Assessments

Support

  • Contact Us
  • FAQ
  • Privacy Policy
  • T&C

Backed By

ah! ventures

Copyright 2023 - All Rights Reserved.

Recommended from DAppWorld
img
1 May 2021
How to connect Ganache with Metamask and deploy Smart contracts on remix without
Set up your development environment with (Metamask + Ganache + Remix) and skip truffle :)
3 min read
11509
5
img
8 Jul 2021
How to interact with smart contarct from backend node js
call and send functions from backend server side using nodejs
3 min read
8103
2
img
18 Aug 2021
Send transaction with web3 using python
Introduction to web3.py and sending transaction on testnet
3 min read
6229
5
img
5 Aug 2021
Deploy Smart Contract on Polygon POS using Hardhat
how to deploy smart contracts on polygon pos chain using hardhat both mainnet and testnet ?
3 min read
5540
3