0

I am creating a contract to buy and sell different tokens in batches. and i want to ensure that all the transactions that would buy or sell the individual tokens, either pass or fail.

my code would be something like this

uint256 amountx = 100
tokenOneContract(tokenOneAddress).transfer(address(this), to, amountx)
tokenTwoContract(tokenTwoAddress).transfer(to, address(this), amountx)

considering i have control over both token Contracts, if the second call (tokenTwoContract) fails and the whole transaction that these calls are part of fails and get reverted, does the tokenOneContract call also get reverted and the transfer of tokenOne fail ? or is there a way for it to pass.

if there is a way for it to pass, how can I force all calls like that to fail if one fails?

i know of optimistic transfers that would check the balances and or do estimate gas fees but that would be the second approach if there is some other atomiticty feature.

1

In the case where the calls are inside a solidity function

function foo() public {
    uint256 amountx = 100
    tokenOneContract(tokenOneAddress).transfer(address(this), to, amountx)
    tokenTwoContract(tokenTwoAddress).transfer(to, address(this), amountx);
}

Then either both functions will succeed or if any of them fails the whole transaction will revert.

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.