How should I charge storage fees?

Viewed 61

What are the best practices of charging storage frees from user? Will I have to charge the storage fees every time they insert the data? Can I charge storage fees without making a function [payable]?

1 Answers

What are the best practices of charging storage frees from user?

There is a Standard designed for this use case:

You can use the interface of this standard in rust from this implementation in near-sdk-rs.

In particular one useful example, is the implementation of this trait for FungibleToken. This functions are exposed using this macro.

Will I have to charge the storage fees every time they insert the data?

If it is clear what is the amount of data a single user requires, they only need to call storage_deposit once, with the required deposit. Optionally they can call storage_withdraw / storage_unregister to get a refund and remove their data.

Can I charge storage fees without making a function [payable]?

No. But if you follow previous standard, only storage_deposit needs to be #[payable] and not other functions in your contract.

Related