In MainContract, I need to perform an atomic transaction which includes the following:

  1. Transfer eth from Contract1 (which is an ERC20 contract) into a given address
  2. Change a state variable in Contract2

I'm having problem implementing the first part.

At present, what I have in mind is to add this in Contract1:

address public mainContract;

constructor(address _mainContract) public {
    mainContract = _mainContract;

function withdraw(address _to, uint256 _value) external {
     require(msg.sender == mainContract);

And then to call function withdraw from a function in MainContract:

function execute(address _to, uint256 _value) external {
     require(msg.sender == owner);
     contract1.withdraw(_to, _value);

But since Contract1 is an ERC20 contract, I was hoping there would be a cleaner way.

Given that I'm the owner of all contracts here, is there a way for me to directly transfer eth from contract1 to the specified address _to?

Something like _to.transfer(_value, {from: address(contract1)}) perhaps?

Thank you!

Note: The reason why I've mentioned the second part (contract2) here, is because otherwise you could tell me something like - "well, just do it from the offchain and get it over with". I need both operations to take place within a single transaction, in order to make sure that nothing else happens in between.


Currently, there’s three main issues with recurring crypto payments or pre-authorized payments in your case.

  • Volatility. Accepting 1ETH/BTC is not suitable for any merchant. Trying to program stability into smart contracts also comes at the cost of decentralisation.

  • User Experience. Pooling money upfront into a smart contract is bad user experience and also requires you to have more money than you have on hand.

  • Scheduling. You can’t have a smart contract call itself at a later point in time.

8x Protocol aims to solve these issues through:

  • Use of stable coin such as MakerDAO to solve volatility. 1 DAI = $1 USD.

  • Usage of ERC20 approve function to allow funds to be taken directly from your wallet. Think: direct debit but for crypto.

  • Network of decentralised nodes who are incentives to trigger the payment at the time that it’s due.

We’re still developing our codebase at: github.com/8xprotocol, although you can find out more about how we’re solving the recurring/subscription crypto payments problem via the Ethereum blockchain at: 8xprotocol.com

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.