1

As the documentation states

get_esdt_balance(address: &ManagedAddress, token_id: &TokenIdentifier, nonce: u64) -> BigUint

will return the balance but it only works if the address is in the same shard as the smart contract? Is there a known alternative or a smart way to make this work for when the address is indeed in a different shard?

Razvan M.
  • 407
  • 5
  • 14

2 Answers2

1

I believe there is no way currently to do what you want. Probably you should change the way you think regarding this, maybe have the user send the ESDT to your contract, do the check and send the ESDT back?

Raress96
  • 214
  • 3
  • 7
  • 1
    I was thinking this could be one way to do it but it seems a bit cumbersome. Was thinking maybe someone has a more elegant solution. – Razvan M. Jan 14 '22 at 16:01
1

There is no way to retrieve the balance of the user without doing a cross-shard call. I would also see it as bad practice to rely on the user having a certain balance since tokens are easily transferable and you won't get any security from doing so.

However, if you really want to do that (without having to rely on snapshots or similar mechanics) you would have to deploy a smart contract on each shard that has an endpoint to check for the user's balance and call that using an async call.

Martin W
  • 733
  • 4
  • 12