2

I have few child wallets and a parent wallet. Whenever these child wallets get incoming ERC20 tokens or ETH. I want to send them automatically to the parent wallet.

I know I can do below to send the entire eth balance.

beneficiary.transfer(this.balance);

How can I do it for erc20 tokens.

Thanks in advance.

1

It's not really possible to do this automatically with the current, ERC20, token standard - and it's seen as a failing, and inconsistency, of this early standard.

That is why new 'advanced' token standards such as ERC223, ERC777 & ERC827 are being developed to handle the situation where the transfer of tokens to a contract can trigger an action.

  • So, you are saying with ERC20 we cannot trigger action when the tokens are sent to contract. SO instead can we have a scheduled event to check if we have token balance in the wallet and send them all to the parent wallet. And one more thing if we do not have ETH balance and have only ERC20 tokens how can pay the gas fees for transfer. – Strikers Mar 15 '18 at 4:05
0

You need to follow the below steps. Consider this as abstract steps, you will have to implement it further.

  1. Define the interface of the token with its transfer method in it.
  2. On the contract create a variable for that interface and assign the token contract address to it.
  3. On the transfer function call token.transfer(beneficiary,tokenBalance
0

You are looking to effectively 'forward' your balance. A way to go about doing this is using a contract similar to the one highlighted Here.

pragma solidity ^0.4.18;

/**
 * Contract that will forward any incoming Ether to its creator
 */
contract Forwarder {
  // Address to which any funds sent to this contract will be forwarded
  address public destinationAddress;

  /**
   * Create the contract, and set the destination address to that of the creator
   */
  function Forwarder() public {
    destinationAddress = msg.sender;
  }

  /**
   * Default function; Gets called when Ether is deposited, and forwards it to the destination address
   */
  function() payable public {
        destinationAddress.transfer(msg.value);
  }

  /**
   * It is possible that funds were sent to this address before the contract was deployed.
   * We can flush those funds to the destination address.
   */
  function flush() public {
    destinationAddress.transfer(this.balance);
  }

}
  • Let me know if you have any questions or if this is too low-level. – Vignesh Karthikeyan Jun 8 '18 at 16:56
  • I'm more concerned about the erc20 tokens more than the ETH itself. – Strikers Jun 11 '18 at 5:35
0

Agree with @SteveJackson. This is a limitation of ERC20.

If these child contracts will be contracts then you can implement the CanReclaimToken solution. https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/CanReclaimToken.sol

This sets up the contracts to allow for recovery of arbitrary tokens that end up in the contract's possession. The Owner passes in the address of the ERC20 to recover the balance of unexpected tokens.

In practical terms, you can consider making a software client that maintains a list of known ERC20 contracts by observing a source then observes those token contracts to see if any transactions arrive for any of the child contracts.

It would then be a matter of invoking the reclaimToken() as Owner.

Certainly, some implementation details to work out but it would be a workable approach if this an important issue.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.