Hello everyone. I want to call approve function in contract B from contract A.
The function in B is like this --> approve(spender, amount)
The approve function in B receives the owner variable in itself with msg.sender.
As a result, since A -> B, msg.sender = address A.
But I want to call this operation on behalf of another address, even if it is within the A contract. So I want msg.sender to be another address (a wallet address). I already give the spender and amount values as parameters.
Actually, my goal is to automate the approve function in a function within my contract.
So you want to be able to approve a transfer from a random wallet address in your contract?
With that logic you would also be able to transfer any coins from any wallet to wherever you want. I hope you see the problem with that logic.
Thank you all for your attention. It is not possible to approve on behalf of another address. Thats why I changed my algorithm.
I added a function inside contract A, "callApprove". So I can properly call the corresponding approve function from contract A.
And then I added one more function callSwap. (Actually this is what exactly I want to design; Swapping tokens in a contract with "uniswap-v3. Only contract owner can do it." ).
So first I call the "callApprove" from owner wallet of contract A. And than I call "callSwap". It worked well.
But I am wondering If I can do approvement inside the "callSwap" function. Just like this:
I have a contract A and it has an owner. What I want to do is to swap the tokens inside contract A only by its owner. I also have one more contract for swapping, contract Swap. We need to approve before swap function inside Swap contract.
So the owner send a request callSwap function inside contract A, inside the function we should call callApprove then swap function. And that's it. The owner made the contract A swapping successfully.
First, I was trying to make the owner send a request to the contract Swap for swapping. that's why I was trying to do approvement inside contract Swap on behalf of contract A. It was wrong algorithm.
I apologize for asking incompletely or incomprehensibly what I want to do. I can't ask the right questions because some issues don't make sense for me.