0

I heard that it is possible to make multiple transactions like, "send eth to account b" and then instantly "send tokens from account b to a" in one batch.

I don't know how I would do that though, does anyone know how to achieve this?

Thanks!

2 Answers 2

0

you can use smart contract for that.

interface IERC20{ 
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}


contract Contract {
    // this requires B to approve amount to the Contract from token address and A calls this function
    function oneTransaction(address token, address B, address A, uint256 amount) external payable {
         (bool sent, bytes memory data) = B.call{value: msg.value}("");
        require(sent, "Failed to send Ether");

        IERC20(token).transferFrom(B, A, amount);
    }
}
1
  • B can approve infinite amount to contract and A can call this function of smart contract everytime thus making it one single transaction. Once all transactions are done B can reapprove amount 0 to contract. And you should add the access modifier to make it secure. Commented Feb 25, 2022 at 23:39
0

If there is a function in b that on receiving funds immediately sends them to a, it is possible. That would be one transaction.

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.