Update a Cairo Felt252Dict through its entry handle
A Cairo dictionary update is recorded as an access with a previous and a new value. The entry API lets code compute a replacement without splitting the operation into an independent read and insert.
Finish the update with the returned entry
For a dictionary of u64 credits, acquire entry(7), obtaining the entry handle and the old value. Add four with the intended overflow behavior, then finalize the handle with fourteen. Continue with the returned dictionary.
old value for key 7 = 10
credit = 4
finalized entry = 14
A missing key in a compatible zero-default numeric dictionary starts with zero. Include both an existing key and a fresh key in tests so initialization does not mask a mistaken replacement of the previous balance.
Keep memory dictionaries distinct from contract storage
Felt252Dict belongs to Cairo execution memory and uses access records and squashing to enforce consistency. Persist values using an appropriate contract storage structure if they must survive the call. A memory-only successful update disappears from the next transaction’s state. starknet.io The Cairo Programming Language