Contract Interfaces

Is there a standard way to declare an ABI and then call a contract address using that ABI?

I didn’t see any mention of this in the documentation so apologies if I missed something!

  • alphak3y

Found my answer here:

2 Likes

Hey @alphaK3Y, I am glad you found a solution to your issue. Lmk if you want any more help :slight_smile:

1 Like

By importing the ContractA ABI, you can make a call to a contract supporting the ContractA interface.

// ./contract_b.sw
contract;
 
use contract_a::ContractA;
 
abi ContractB {
    fn make_call();
}
 
const contract_id = 0x79fa8779bed2f36c3581d01c79df8da45eee09fac1fd76a5a656e16326317ef0;
 
impl ContractB for Contract {
    fn make_call() {
      let x = abi(ContractA, contract_id);
      let return_value = x.receive(true, 3); // will be 45
    }
}
2 Likes