
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...
I turn programmers into professional Web3 developers.

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...
I turn programmers into professional Web3 developers.
Share Dialog
Share Dialog

Subscribe to Marco Besier

Subscribe to Marco Besier


<100 subscribers
<100 subscribers
Solidity interfaces are an essential tool that allows smart contracts to interact with existing smart contracts. In this blog post, we will explore how to use Solidity interfaces to interact with existing smart contracts.
Solidity interfaces are contracts that define the structure of another contract without providing any implementation. They are like a blueprint or a template that describes the functions, variables, and events of an existing smart contract. In particular, you can use interfaces to define the structure of an external contract that you wish to interact with inside your own contracts.
Interfaces are defined using the interface keyword, followed by the name of the interface, and the functions, variables, and events it defines. Here is an example of a simple Solidity interface:
interface ExternalContractInterface {
function externalFunction() external returns (uint);
}
In this example, we define an interface named ExternalContractInterface that includes a function called externalFunction. The external keyword is used to indicate that this function can be called from outside the external contract, e.g., by the contracts you create yourself. Furthermore, the interface specifies that the function returns an unsigned integer.
Here is an example of how you can use the ExternalContractInterface interface from an external contract inside your own contract code:
pragma solidity ^0.8.0;
interface ExternalContractInterface {
function externalFunction() external returns (uint);
}
contract MyContract {
ExternalContractInterface private externalContract;
constructor(address _addressOfExternalContract) {
externalContract = ExternalContractInterface(_addressOfExternalContract);
}
function callExternalFunction() public view returns (uint) {
return externalContract.externalFunction();
}
}
In this example, we first define the ExternalContractInterface interface and subsequently define a contract called MyContract that includes a private variable externalContract of type ExternalContractInterface. We also define a constructor that takes an address parameter _addressOfExternalContract to initialize externalContract.
The callExternalFunction function is a public view function that returns the result of calling the externalFunction function from externalContract.
By using the interface, we can interact with the functions of the external contract in a type-safe manner. This means that we can verify the contract address and the function signatures at compile time, reducing the risk of errors at runtime.
Solidity interfaces are an essential part of your toolbox as a Web3 developer. They enable you to code smart contracts that can interact with other, external contracts that are already live on mainnet. By using interfaces, you can ensure that the contract addresses and function signatures are correct at compile time, reducing the risk of errors at runtime. As you can see, Solidity interfaces are a powerful tool that you can leverage to build complex decentralized applications on any EVM-compatible blockchain.
Solidity interfaces are an essential tool that allows smart contracts to interact with existing smart contracts. In this blog post, we will explore how to use Solidity interfaces to interact with existing smart contracts.
Solidity interfaces are contracts that define the structure of another contract without providing any implementation. They are like a blueprint or a template that describes the functions, variables, and events of an existing smart contract. In particular, you can use interfaces to define the structure of an external contract that you wish to interact with inside your own contracts.
Interfaces are defined using the interface keyword, followed by the name of the interface, and the functions, variables, and events it defines. Here is an example of a simple Solidity interface:
interface ExternalContractInterface {
function externalFunction() external returns (uint);
}
In this example, we define an interface named ExternalContractInterface that includes a function called externalFunction. The external keyword is used to indicate that this function can be called from outside the external contract, e.g., by the contracts you create yourself. Furthermore, the interface specifies that the function returns an unsigned integer.
Here is an example of how you can use the ExternalContractInterface interface from an external contract inside your own contract code:
pragma solidity ^0.8.0;
interface ExternalContractInterface {
function externalFunction() external returns (uint);
}
contract MyContract {
ExternalContractInterface private externalContract;
constructor(address _addressOfExternalContract) {
externalContract = ExternalContractInterface(_addressOfExternalContract);
}
function callExternalFunction() public view returns (uint) {
return externalContract.externalFunction();
}
}
In this example, we first define the ExternalContractInterface interface and subsequently define a contract called MyContract that includes a private variable externalContract of type ExternalContractInterface. We also define a constructor that takes an address parameter _addressOfExternalContract to initialize externalContract.
The callExternalFunction function is a public view function that returns the result of calling the externalFunction function from externalContract.
By using the interface, we can interact with the functions of the external contract in a type-safe manner. This means that we can verify the contract address and the function signatures at compile time, reducing the risk of errors at runtime.
Solidity interfaces are an essential part of your toolbox as a Web3 developer. They enable you to code smart contracts that can interact with other, external contracts that are already live on mainnet. By using interfaces, you can ensure that the contract addresses and function signatures are correct at compile time, reducing the risk of errors at runtime. As you can see, Solidity interfaces are a powerful tool that you can leverage to build complex decentralized applications on any EVM-compatible blockchain.
No activity yet