In Sway, you can define an abstract contract using an ABI and then implement that ABI in another contract. Here’s how you can create two contracts, A and B, where A is abstract and B inherits from A and overrides a function.
Not too sure if this is the way in creating abstract contract to inherit it.
Contract A (Abstract)
Define an abstract contract with a function that returns 0:
// Contract A
contract;
abi ContractA {
fn return_value() -> u64;
}
impl ContractA for Contract {
fn return_value() -> u64 {
0
}
}
Contract B (Inherits A)
Implement Contract B to inherit from Contract A and override the function to return 1:
// Contract B
contract;
use contract_a::ContractA;
abi ContractB {
fn return_value() -> u64;
}
impl ContractB for Contract {
fn return_value() -> u64 {
1
}
}
Can we use the same abi? From the post here, using the same ABI would have issue. Failed to compile contracts without error logs - #8 by Nazeeh21