9

Say I want to make a transaction that calls foo() and the calls bar() afterwards. I could make a contract that calls them both in sequence, but that's kind of a pain. Is there a way to just call both without prompting the user for multiple signatures? And if so will foo() revert if bar() reverts and vice versa?

3 Answers 3

7

There is no way to do this without using a contract.

In general, due to Ethereum's "no features" design principle, anything more complex than a simple transaction will require a smart contract. In this case the contract would be very small, and you can simply deploy it once and reuse it.

2
3

You may call all in one transaction by deploying contract looking like this:

contract Target {
    function foo () public;
    function bar () public;
}

contract Batch {
  constructor (Target target) public {
    target.foo ();
    target.bar ();
    selfdestruct (msg.sender);
  }
}

This will revert foo() in case bar() will fail.

Though, this will call foo() and bar() from temporary smart contract address rather than from your real address.

1

The user signs one transaction. It can involve many contracts and functions, according to design. It will also be atomic - completing or reverting entirely.

There is no way to have the user sign two such transactions or receive the same assurances about two separately signed transactions.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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