On CrytpoKitties, when I tap the buy button in a market, MetaMask comes up and shows if I can buy or not based on allowance instantly. How is this possible? Is it making query? Is it included in kitty's contract?
Yes, Metamask is checking if you have approved the tokens to be spent by the Cryptokitty smart contract.
If the dapp is transferring tokens on the user's behalf (i.e. calling
transferFrom()), then the dapp must check if the user has the proper
In order to use
transferFrom(), the user must allow a contract to spend tokens on their behalf. To do this, the user must first
approve() a certain amount of tokens that they are willing to the let the dapp transfer. The dapp must confirm that the user has an adequate
allowance() before calling the
transferFrom() function, or else it will fail.