From the ink! cross-contract docs, contract references give developers a type-safe way of interacting with a contract. However, this is not only available when the contract is already instantiated.
My question is, given the
AccountId or code hash of the contract, is there a way to convert that to a
ContractRef so I'm sure that
AccountId really points to a contract with the expected type?
Currently, ink! has the
CallBuilder but this doesn't ensure the contract is of the expected type.
For instance, supposed I've 3 contracts. The first contract has the main struct named
First, the second
Second, and the third
Third. Assume both
Second has a method called
flip. Within the
Third contract, if I want to call the
flip method from the already instantiated
First contract, implementing it would be:
let my_return_value = build_call::<DefaultEnvironment>() .call(contracts_address) .gas_limit(0) .transferred_value(10) .exec_input( ExecutionInput::new(Selector::new(ink::selector_bytes!("flip"))) .push_arg(42u8) ) .returns::<bool>() .invoke();
However this doesn't ensure only the
First contract's flip method is called. Using the
Second contract's address would also work.