Check recipient storage registration before a NEAR token transfer
A recipient can have a valid NEAR account while the token contract has no storage entry for it. For a token implementing NEP-145, a view call resolves that distinction.
Query the recipient on the correct token contract
The encoded argument below represents {"account_id":"alice.testnet"}. Replace the contract and re-encode the JSON when changing recipients. Decode the result byte array as UTF-8 JSON.
{
"jsonrpc": "2.0",
"id": 1,
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "token.testnet",
"method_name": "storage_balance_of",
"args_base64": "eyJhY2NvdW50X2lkIjoiYWxpY2UudGVzdG5ldCJ9"
}
}
Distinguish a missing entry from zero available storage
A decoded null means there is no registration. An object with total greater than zero and available equal to "0" indicates an existing registration with no withdrawable storage balance. Such an account does not need a second initial registration simply because available is zero.
For an unregistered recipient, read storage_balance_bounds on the same token contract to determine its minimum before preparing a storage_deposit. Record the observed state because another transaction may register the recipient first.