Interfaces
Used to create the ABI of a referenced contract without having to actually include all the functions
So you say "This contract that I'm referencing has a
fund()function"This means it can be called, but you don't actually need to know what happens inside the function, you just need to know the name and inputs
Using an Interface
interface NumberInterface {
function getNum(address _myAddress) external view returns (uint);
}
contract MyContract {
address NumberInterfaceAddress = 0xab38...
NumberInterface numberContract = NumberInterface(NumberInterfaceAddress);
function someFunction() public {
uint num = numberContract.getNum(msg.sender);
}
}In this way, your contract can interact with any other contract on the Ethereum blockchain, as long they expose those functions as public or external.
Example
Last updated