shidiq

seseorang yang berusaha untuk hidup

β€’
proses β€’ 2 menit baca

Proses Hari ke 70

glooomiz-vtuber

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

  1. πŸ“• What do you need to interact with an external contract?

  2. πŸ§‘β€πŸ’» 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.

Deployed Contract

Inheritance in Solidity

πŸ§‘β€πŸ’» Test yourself

  1. πŸ“• Why do we need inheritance to extend a contract’s functionality?

  2. πŸ“• How are the keywords override and virtual used together?

  3. πŸ§‘β€πŸ’» 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

SOLIDITY
function store(uint256 favNumber) public virtual {
    favoriteNumber = favNumber;
}

Squared.sol

SOLIDITY
// 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;
    }
}

Β© 2026 Shidiq. All rights reserved.