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
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.
- 37,046
- 10
- 91
- 118
-
So even the BatchRequest is not atomic? https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#batchrequest – jerryleooo Feb 20 '22 at 14:27
-
2That simply batches requests from the web3 insurance to the backing node/provider. The requests are still sent to the network separately and are not atomic – Tjaden Hess Feb 20 '22 at 22:36
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.
- 7,313
- 1
- 23
- 38
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.
- 55,151
- 11
- 89
- 145