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 to/from smart contracts 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");
In this example the erc20 contract that it interacts with is stored in contract A
. This can, however, be given as an argument as well:
fn transfer_from_contract_a(&self, to: AccountId, value: Balance, erc20_as_argument: AccountId) {
build_call::<DefaultEnvironment>()
.call(erc20_as_argument)
...
}
contract A
which takes as argument anothercontract B
.Contract A
will then transfer its tokens tocontract B
. What kind of token do you want to transfer?