Ethers.js: Multiple smart-contract function calls in one transaction

Created on 22 Sep 2020  路  3Comments  路  Source: ethers-io/ethers.js

Hello,

Sorry if my question is redundant due to me not understanding fully Ethereum.
I'd like to send a transaction in which I would perform two smart-contract calls (write/signed).
In this specific case, it would be about call the same smart-contract function with different parameters.
The calls would need to be sequential but atomic - occurring in the same block - and the transaction would need to fail if one of the calls fails.

My intuition tells me that the best way to perform this would be to create a proxy smart-contract in which I would wrap the calls to the target smart contract, hence I would only need to perform one transaction and the smart-contract would make the two calls. I think I understand that a "revert" occurs if a single error occurs during a transaction, which would be my desired behavior.

However in the issues of this repo, I often see the notions of multi-call, or batch requests, supposedly supported by web3. That makes me wonder if ether.js is planning to support such a feature, or if it is at least technically possible with Ethereum. However those issues often mention HTTP, which seems to suggest that it's only talking about RPC requests batching and not merging multiple calls in a signed Ethereum transaction.

So, proxy smart-contract or other solutions possible ?

Thank you.

discussion

Most helpful comment

Heya!

You are correct. A proxy contract is the only way (currently, in the future we may get rich transactions) to do what you want. In which case keep in mind the address of the contract will be the msg.sender in the forwarded calls (so, for example if you are trying to send and erc-20 token, it is coming from your proxy, not your eoa).

Batch calls are quite un-related and almost no one ever needs them; people often misunderstand their purpose (their purpose doesn鈥檛 actually make sense in the context of Ethereum, they are a consequence of the JSON-RPC specification).

And a multi-call is similar to what you are talking about, which is a custom contract designed to make multiple calls on the callers behalf, but many are not general purpose enough for your uses.

So, long story short, your proxy method is what you are interested in. :)

All 3 comments

Heya!

You are correct. A proxy contract is the only way (currently, in the future we may get rich transactions) to do what you want. In which case keep in mind the address of the contract will be the msg.sender in the forwarded calls (so, for example if you are trying to send and erc-20 token, it is coming from your proxy, not your eoa).

Batch calls are quite un-related and almost no one ever needs them; people often misunderstand their purpose (their purpose doesn鈥檛 actually make sense in the context of Ethereum, they are a consequence of the JSON-RPC specification).

And a multi-call is similar to what you are talking about, which is a custom contract designed to make multiple calls on the callers behalf, but many are not general purpose enough for your uses.

So, long story short, your proxy method is what you are interested in. :)

I think this question has been answered, so I'm going to close it. If you have further questions though, please feel free to re-open.

Thanks! :)

Batch calls are quite un-related and almost no one ever needs them;

Could you explain this a little more? I recently stumbled on web3.js's batchrequest and it seems like the use-case here is you want to reduce the number of roundtrips to your node or node-provider, which would result in speed improvements.

Why doesn't this make sense in the context of Ethereum?

btw, just want to say thank you for your in depth replies to numerous issues across this repo, I have learned a lot from them :).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricmoo picture ricmoo  路  3Comments

adamdossa picture adamdossa  路  3Comments

thegostep picture thegostep  路  3Comments

crazyrabbitLTC picture crazyrabbitLTC  路  3Comments

GFJHogue picture GFJHogue  路  3Comments