Skip to main content
added 781 characters in body
Source Link
Daan - R0GUE
  • 2.9k
  • 3
  • 25

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)
                ...
        }

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");

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)
                ...
        }

added 781 characters in body
Source Link
Daan - R0GUE
  • 2.9k
  • 3
  • 25

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 bB.

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");

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.

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");
Source Link
Daan - R0GUE
  • 2.9k
  • 3
  • 25

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.