the value is replaced with available gas right?
As a bit of a simplification, yes.
IIRC, I believe the amount of gas forwarded to the callee is actually 63/64ths of the remaining gas in the transaction.
There are a bunch of questions here which I will try to unpack.
1. How to get its return value?
When a contract terminates in the EVM, it has a halting state, denoted H. This halting state takes three possible values:
() when execution needs to halt without return value
the empty set, let's call it None when execution needs to continue
or a list of two ...
No there is no way to know it reliably. Even sending the same transaction multiple times may result in different gas amounts. (See for example here Why gas-used are different for same transfer() tx? ). Also other factors make it difficult/impossible to estimate it correctly, such as loops (can we know in advance how many times we will loop?).
The amount can ...
Try our official ERC721 implementation. Here is also a working example described in our test case. See also a link to the ERC721 receiver mock and a direct link to the safeTransferFrom implementation.