I turn programmers into professional Web3 developers.
I turn programmers into professional Web3 developers.

Subscribe to Marco Besier

Subscribe to Marco Besier
<100 subscribers
<100 subscribers
Share Dialog
Share Dialog

The "virtual" and "override" keywords in Solidity
Solidity has two keywords that are crucial to understand if you want to make use of contract inheritance: virtual and override. In this blog post, we'll take a closer look at these keywords and explore how you can use them in Solidity.Virtual functionsA virtual function is a function that a derived contract can override. You can mark a function as virtual by using the virtual keyword. If a derived contract overrides a virtual function, it must use the override keyword. Here's an exa...

Zero-knowledge proofs in plain English
In this post, I’ll try to demystify one of the most confusing topics in cryptography: zero-knowledge proofs. However, instead of delving into the mathematical details of ZKPs, my goal is to provide you with an easy-to-remember example that explains the basic concept behind ZKPs in plain English.Defining ZKPsTo start, let’s take a look at how Wikipedia introduces zero-knowledge proofs: In cryptography, a zero-knowledge proof is a method by which one party (the prover) can prove to another part...

The "virtual" and "override" keywords in Solidity
Solidity has two keywords that are crucial to understand if you want to make use of contract inheritance: virtual and override. In this blog post, we'll take a closer look at these keywords and explore how you can use them in Solidity.Virtual functionsA virtual function is a function that a derived contract can override. You can mark a function as virtual by using the virtual keyword. If a derived contract overrides a virtual function, it must use the override keyword. Here's an exa...

Zero-knowledge proofs in plain English
In this post, I’ll try to demystify one of the most confusing topics in cryptography: zero-knowledge proofs. However, instead of delving into the mathematical details of ZKPs, my goal is to provide you with an easy-to-remember example that explains the basic concept behind ZKPs in plain English.Defining ZKPsTo start, let’s take a look at how Wikipedia introduces zero-knowledge proofs: In cryptography, a zero-knowledge proof is a method by which one party (the prover) can prove to another part...


Solidity functions have four different visibility modifiers that determine where and how they can be called. The four visibility modifiers are public, private, internal, and external. In this blog post, we'll explore each of these modifiers in detail.
A public function is visible to all other contracts and can be called both internally and externally. Here's an example:
contract MyContract {
uint public myNumber;
function setNumber(uint _number) public {
myNumber = _number;
}
}
In this example, the setNumber function is marked as public, which means it can be called both internally and externally. The function takes a single parameter _number and sets the myNumber variable to its value.
A private function is only visible within the contract that defines it. Here's an example:
contract MyContract {
uint private myNumber;
function _setNumber(uint _number) private {
myNumber = _number;
}
function getNumber() public view returns (uint) {
return myNumber;
}
}
In this example, the _setNumber function is marked as private, which means it can only be called within the same contract. The function takes a single parameter _number and sets the myNumber variable to its value. The getNumber function is marked as public and can be called both internally and externally to retrieve the value of myNumber.
An internal function is visible to the contract that defines it and any contracts that inherit from it. Here's an example:
contract MyContract {
uint internal myNumber;
function _setNumber(uint _number) internal {
myNumber = _number;
}
}
contract MyDerivedContract is MyContract {
function setNumber(uint _number) public {
_setNumber(_number);
}
function getNumber() public view returns (uint) {
return myNumber;
}
}
In this example, the _setNumber function is marked as internal, which means it can be called within the same contract and any contracts that inherit from it. The MyDerivedContract contract inherits from MyContract, so it can call the _setNumber function. The setNumber function is marked as public and calls the _setNumber function to set the value of myNumber. The getNumber function is also marked as public and can be called both internally and externally to retrieve the value of myNumber.
An external function is only visible externally and can only be called externally. Here's an example:
contract MyContract {
function sayHello(string memory _name) external pure returns (string memory) {
return string(abi.encodePacked("Hello, ", _name, "!"));
}
}
In this example, the sayHello function is marked as external, which means it can only be called externally. The function takes a single parameter _name and returns a string that says "Hello, [name]!" using the abi.encodePacked function to concatenate the strings. The function is also marked as pure, which means it doesn't read or modify the state of the contract.
Solidity function visibility modifiers are an important aspect of writing secure and efficient smart contracts. Understanding the differences between public, private, internal, and external functions is crucial if you want to control where and how your contract’s functions can be called.
To become a skilled Web3 developer and master blockchain development, I invite you to join the Web3 Developer Academy. Inside the free membership, you’ll get free access to our “Intro to Web3 Development” video course and a global community of 100+ aspiring Web3 developers like you. Take your blockchain development skills to the next level by joining the Web3 Developer Academy today.
Solidity functions have four different visibility modifiers that determine where and how they can be called. The four visibility modifiers are public, private, internal, and external. In this blog post, we'll explore each of these modifiers in detail.
A public function is visible to all other contracts and can be called both internally and externally. Here's an example:
contract MyContract {
uint public myNumber;
function setNumber(uint _number) public {
myNumber = _number;
}
}
In this example, the setNumber function is marked as public, which means it can be called both internally and externally. The function takes a single parameter _number and sets the myNumber variable to its value.
A private function is only visible within the contract that defines it. Here's an example:
contract MyContract {
uint private myNumber;
function _setNumber(uint _number) private {
myNumber = _number;
}
function getNumber() public view returns (uint) {
return myNumber;
}
}
In this example, the _setNumber function is marked as private, which means it can only be called within the same contract. The function takes a single parameter _number and sets the myNumber variable to its value. The getNumber function is marked as public and can be called both internally and externally to retrieve the value of myNumber.
An internal function is visible to the contract that defines it and any contracts that inherit from it. Here's an example:
contract MyContract {
uint internal myNumber;
function _setNumber(uint _number) internal {
myNumber = _number;
}
}
contract MyDerivedContract is MyContract {
function setNumber(uint _number) public {
_setNumber(_number);
}
function getNumber() public view returns (uint) {
return myNumber;
}
}
In this example, the _setNumber function is marked as internal, which means it can be called within the same contract and any contracts that inherit from it. The MyDerivedContract contract inherits from MyContract, so it can call the _setNumber function. The setNumber function is marked as public and calls the _setNumber function to set the value of myNumber. The getNumber function is also marked as public and can be called both internally and externally to retrieve the value of myNumber.
An external function is only visible externally and can only be called externally. Here's an example:
contract MyContract {
function sayHello(string memory _name) external pure returns (string memory) {
return string(abi.encodePacked("Hello, ", _name, "!"));
}
}
In this example, the sayHello function is marked as external, which means it can only be called externally. The function takes a single parameter _name and returns a string that says "Hello, [name]!" using the abi.encodePacked function to concatenate the strings. The function is also marked as pure, which means it doesn't read or modify the state of the contract.
Solidity function visibility modifiers are an important aspect of writing secure and efficient smart contracts. Understanding the differences between public, private, internal, and external functions is crucial if you want to control where and how your contract’s functions can be called.
To become a skilled Web3 developer and master blockchain development, I invite you to join the Web3 Developer Academy. Inside the free membership, you’ll get free access to our “Intro to Web3 Development” video course and a global community of 100+ aspiring Web3 developers like you. Take your blockchain development skills to the next level by joining the Web3 Developer Academy today.
No activity yet