Loading...
Function and state variables have to declare whether they are accessible by other contracts.
--- Only other contracts and accounts can call
--- any contract and account can call
--- only inside the contract that inherits as an internal function.
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();
}
}