Yes this is possible.
When instantiating a smart contract it gets an account id, just like a user has an account id. This means that transfering tokens works the same.
Therefore, e.g. for the ERC20 contract, you can call fn transfer
with parameter to
the account id of contract B
.
I'm not sure if you still need contract A
with this knowledge. But if you do, you can do something similar like:
fn transfer_from_contract_a(&self, to: AccountId, value: Balance) {
build_call::<DefaultEnvironment>()
.call(self.erc20_contract)
.gas_limit(0)
.transferred_value(0)
.call_flags(CallFlags::default().set_tail_call(true))
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("transfer")))
.push_arg(caller),
.push_arg(value),
)
.returns::<()>()
.try_invoke();
.unreachable!("set_tail_call = true");