Is it possible to make multiple function calls in a single transaction?

by skrrrraaaa   Last Updated April 15, 2019 14:28 PM

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?

Tags : transactions


Answers 3


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.

Tjaden Hess
Tjaden Hess
April 15, 2019 14:05 PM

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.

Rob Hitchens
Rob Hitchens
April 15, 2019 14:09 PM

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.

Mikhail Vladimirov
Mikhail Vladimirov
April 15, 2019 14:25 PM

Related Questions


Updated October 02, 2017 06:28 AM

Updated December 04, 2017 03:28 AM

Updated January 26, 2018 10:28 AM

Updated April 18, 2018 12:28 PM

Updated March 10, 2019 15:28 PM