What is the difference in these two approaches for cross contract calls? One uses the {Contract}Ref
and the other uses the build_call().delegate()
method. Both methods do not require the contract to be instantiated and only require the code hash.
let adder = AdderRef::new(accumulator.clone(), staker_code_hash)
.endowment(0)
.code_hash(adder_code_hash)
.salt_bytes(salt)
.instantiate();
adder.inc(by)
build_call::<DefaultEnvironment>()
.delegate(self.staker_code_hash)
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("get_stake")))
)
.returns::<i32>()
.try_invoke() {
Ok(value) => value,
Err(err) => match err {
ink_env::Error::Decode(err) => panic!("Failed to decode return value: {:?}", err.to_string()),
_ => panic!("Failed to invoke `stake`"),
}
}
build_call().delegate
, but you can also usebuild_call().call
which takes callee AccountId as a parameter and you do not need hash. docs.rs/ink_env/4.2.0/ink_env/call/… That makesbuild_call()
to be more usable if you call already deployed contract.