Proses Hari ke 70

ABI Contract
ABI adalah singkatan dari Application Binary Interface.
Inheritance
Di solidity, ada juga konsep Inheritance atau pewarisan. Dimana contract bisa mewarisi contract lain. Ini mempermudah saat proses penggabungan contract dibandingkan untuk menginisiasi semua contract didalam sebuah file.
Mengerjakan Soal
Interacting With Contracts ABI
π§βπ» Test yourself
π What do you need to interact with an external contract?
π§βπ» Deploy 3 instances of the SimpleStorage contract through the StorageFactory. Then store some numbers via sfStore and retrieve all of them via sfGet.
1. What do you need to interact with an external contract?
ABI dan contract Address.
2. Deploy 3 instances of the SimpleStorage contract through the StorageFactory. Then store some numbers via sfStore and retrieve all of them via sfGet.
Inheritance in Solidity
π§βπ» Test yourself
π Why do we need inheritance to extend a contractβs functionality?
π How are the keywords override and virtual used together?
π§βπ» Create a contract Squared that overrides the store function and returns the favorite number squared.
1. Why do we need inheritance to extend a contractβs functionality?
Agar bisa menggunakan kembali kode (reuse), menghindari duplikasi, membuat kontrak modular dan lain sebagainya.
2. How are the keywords override and virtual used together?
Keyword virtual digunakan untuk menandai sebuah function agar bisa di-override oleh contract lain. Keyword override digunakan untuk menandai sebuah function agar bisa di-override oleh contract lain.
Virtual ditempatkan pada parent function sedangkan override ditempatkan pada child function.
3. Create a contract Squared that overrides the store function and returns the favorite number squared.
SimpleStorage.sol
function store(uint256 favNumber) public virtual {
favoriteNumber = favNumber;
}Squared.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {SimpleStorage} from "./SimpleStorage.sol";
contract Squared is SimpleStorage {
function store(uint256 _newFavNumber) public override {
favoriteNumber = _newFavNumber * _newFavNumber;
}
}