3

Considering that get_esdt_token_data(address: &ManagedAddress, token_id: &TokenIdentifier, nonce: u64) -> EsdtTokenData<Self::Api> always returns an EsdtTokenData rather than an option. What will this object look like if the address does not own the specified token?

Razvan M.
  • 407
  • 5
  • 14

1 Answers1

2

The execution will fail as the VM will not return anything to the smart contract if it doesn't find the token.

The typical usage for this function is to get the data for the payment tokens the smart contract receives from the caller. If you're trying to use it freely, you might get into this situation, so this type of "free" usage is not really advised.

Brother Jder
  • 415
  • 2
  • 9
  • I am aware that when a smart contract receives a payment in a token, you get the token id. Do you also receive the owner address? If not, how do you get the first argument for the `get_esdt_token_data` method? – rvignolo May 12 '22 at 15:56
  • 2
    For the "owner" address you can simply use the tx caller since that's the address that sent the tokens to the smart contract: `self.blockchain().get_caller()` – Brother Jder May 16 '22 at 10:04