0

Here are smartcontract A and B

B has BuyService function. User need to call this function to get service. A has token(erc20) enough. If user call A without tokens, then A call B and pay tokens on behalf of user. B receive tokens from A and give service to user. B is very regular and simple standard contract.

Can contract A work? If so, can any contract be interacted with A?

0

As I was explaining in your original question I have msg.sender issue there is no such functionality as "call contract with tokens". Tokens are not transferred as part of a call between contracts, they are only transferred by calling the token contract's own transfer (or transferFrom) function.

The problem with token transfers in general is that the contract which receives the tokens has no way of knowing when and if he has received tokens. The only way to know is for the contract to check his own token balance from the token contract but somebody has to trigger the functionality which starts the checking process.

So it could work something like this:

1) User doesn't have tokens and calls A

2) A uses the token contract's transfer function to transfer tokens to B

3) A calls some function in B such as iHaveGivenYouTokens

4) B receives a call to iHaveGivenYouTokens from A and checks his balance from the token contract

5) Seeing that his balance has increased, B performs the service

I'm not sure what you mean with sentences "B is very regular and simple standard contract" and "can any contract be interacted with A". B is not "regular" contract and it doesn't follow any standards - it's a specialized contract which you need to implement. And for the second quote: it's all up to you. If you allow any contract or user to interact with your contracts then that's possible. Or you can restrict access to the contracts based on address for example.

  • When B checks balance of msg.sender while execution of BuyService function, in case of regular call not delegatecall, msg.sender is A so it returns true here. But, B finally give service to A not user. I am asking how I can make contract A that makes B to give service to user. – ikaop May 28 at 11:20
  • B shouldn't check balance of msg.sender. B only cares about his own balance. – Lauri Peltonen May 28 at 11:55

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.